Vlookup using a comma separated search key in Google Sheets - google-sheets

I am trying to use a vlookup (or some other function) to populate a list of numbers with usernames based on comma-separated data appearing in a single cell. I have attempted wild cards, and regmatch functions but can't seem to get the syntax correct (see the development tab of the linked spreadsheet for my efforts).
Essentially, I'd like to populate column B of the "columns" tab with usernames from column E of the All tab that corresponds to the numbers in column A derived from the comma-separated input in column D of the "all" Tab.
https://docs.google.com/spreadsheets/d/1Zebrp15784rtKb8obSr1ohWbjwm28owVTLSf1cBixzs/edit#gid=556664780
Thanks in advance for any support.

Solution without VLOOKUP:
=IFERROR(
INDEX(E:E,
MAX(
IFERROR(MATCH((ROW ()-1) & ",*",D:D,0), -1),
IFERROR(MATCH("* " & (ROW ()-1) & ",*",D:D,0), -1),
IFERROR(MATCH(", " & (ROW ()-1),D:D,0), -1)
),
1),
"")
Explain:
MATCH((ROW ()-1) & ",*",D:D,0) - the first number (9, 15, 21)
MATCH("* " & (ROW ()-1) & ",*",D:D,0) - a middle number (9, 15, 21)
MATCH(", " & (ROW ()-1),D:D,0) - the last number (9, 15, 21)
if no match ROW()-1 with data value will be -1, then it fires ERROR
(when we try to get aname by row == -1)
if we have ERROR we show an empty string
Result:

use:
=INDEX(IFNA(VLOOKUP(A2:A*1, SPLIT(FLATTEN(IF(IFERROR(
SPLIT(ALL!D2:D, ","))="",,SPLIT(ALL!D2:D, ",")&"​"&ALL!E2:E)), "​"), 2, )))

=INDEX(IFNA(VLOOKUP(A2:A*1, SPLIT(FLATTEN(IF(IFERROR(
SPLIT(ALL!D2:D, ","))="",,SPLIT(ALL!D2:D, ",")&"​"&ALL!E2:E)), "​"), 2, )))
This is the formula that worked the best. It treated each of the comma separated values separately and allowed me to pull in the names from the appropriate column. Thanks for the support!

Related

Sheets flag duplicates when Column A and Column B exactly match another row in the column

Column A - First Name
Column B - Last Name
I need sheets to flag when a duplicate appears (we have duplicate submissions for the same person submitted via a google form)
I understand how to make it so that if there's a duplicate in column A it will highlight, however first name is not enough of an identifier (e.g we often have two Joe's that are 2 different people therefore not 'duplicates')
How do I write something that says if Column A & B match exactly show me 'duplicate'?
Thanks
Put this formula in cell C2:
=arrayformula( if( countifs(A2:A, A2:A, B2:B, B2:B) > 1, "duplicate", iferror(1/0) ) )
Alternatively, use this conditional formatting custom formula rule for the range A2:B:
=countifs($A$2:$A, $A2, $B$2:$B, $B2) > 1

Why my ArrayFormula is giving error? How do I correct it? (I'm not looking for another Arrayformula as solutions!)

I wanted a ArrayFormula at C1 which gives the required result as shown.
Entry sheet:
(Column C is my required column)
Date Entered is the date when the Name is Assigned a group i.e. a, b, c, d, e, f
Criteria:
The value of count is purely on basis of Date Entered (if john is assigned a on lowest date(10-Jun) then count value is 1, if rose is assigned a on 2nd lowest date(17-Jun) then count value is 2).
The value of count does not change even when the data is sorted in any manner because Date Entered column values is always permanent & does not change.
New entry date could be any date not necessarily highest date (If a new entry with name Rydu is assigned a on 9-Jun then the it's count value will become 1, then john's (10-Jun) will become 2 and so on)
Example:
After I sort the data in any random order say like this:
Random ordered sheet:
(Count value remains permanent)
And when I do New entries in between (Row 4th & 14th) and after last row (Row 17th):
Random Ordered sheet:
(Doesn't matter where I do)
I already got a ArrayFormula which gives the required result:
={"AF Formula1"; ArrayFormula(IF(B2:B="", "", COUNTIFS(B$2:B, "="&B2:B, D$2:D, <"&D2:D)+1))}
I'm not looking for another Arrayformula as solutions. What I want is to know what is wrong in my ArrayFormula? and how do I correct it?
I tried to figure my own ArrayFormula but it's not working:
I got Formula for each cell:
=RANK($D2,FILTER($D$2:$D, $B$2:$B=$B2),1)
I figured out Filter doesn't work with ArrayFormula so I had to take a different approach.
I took help from my previous question answer (Arrayformula at H3) which was similar since in both cases each cell FILTER formula returns more than 1 value. (It was actually answered by player0)
Using the same technique I came up with this Formula which works absolutely fine :
=RANK($D2, ARRAYFORMULA(TRANSPOSE(SPLIT(VLOOKUP($B2, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ","))), 1)
Now when I tried converting it to ArrayFormula:
($D2 to $D2:$D & $B2 to $B2:$B)
=ARRAYFORMULA(RANK($D2:$D,TRANSPOSE(SPLIT(VLOOKUP($B2:$B, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ",")), 1))
It gives me an error "Did not find value '' in VLOOKUP evaluation", I figured out that the problem is only in VLOOKUP when I change $B2 to $B2:$B.
I'm sure VLOOKUP works with ArrayFormula, I fail to understand where my formula is going wrong! Please help me correct my ArrayFormula.
Here is the editable sheet link
if I understand correctly, you are trying to "rank" B column based on D column dates in such way that dates are in theoretical ascending order so if you randomize your dataset, the "rank" of each entry would stay same and not change based on the randomness you introduce.
therefore the correct formula would be:
={"fx"; INDEX(IFNA(VLOOKUP(B2:B&D2:D,
{INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1),
IFERROR(1/(1/COUNTIFS(
INDEX(SORT(B2:D, 3, 1),,1),
INDEX(SORT(B2:D, 3, 1),,1), ROW(B2:B), "<="&ROW(B2:B))))}, 2, 0)))}
{"fx"; ...} array of 2 tables (header & actual table) under each other eg. ;
outer shorter INDEX or longer ARRAYFORMULA (doesnt matter which one) is needed coz we are processing an array
IFNA for removing possible #N/A errors from VLOOKUP function when VLOOKUP fails to find a match
we VLOOKUP joint B and D column B2:B&D2:D in our virtual table {} and returning second 2 column if there is an exact match 0
our virtual table {INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1), ...} we VLOOKUP from is constructed with 2 columns next to each other eg. ,
we are getting the first column by creating an array of 2 columns {B2:B&D2:D, D2:D} next to each other where we SORT this array by date/2nd column 2, in ascending order 1 but all we need after sorting is the 1st column so we use INDEX where we bring all rows ,, and the first column 1
now lets take a look on how we getting the 2nd column of our virtual table by using COUNTIFS which will mimic the "rank"
IFERROR(1/(1/ is used to remove all zero values from the output (all empty rows would have 0 in it as the "rank")
under COUNTIFS we put 2 pairs of arguments: "if column is qual to column" and "if row is larger or equal to next row increment it by 1" ROW(B2:B), "<="&ROW(B2:B))
for "if column is qual to column" we do this twice and use range B2:D and sort it by date/3rd column 3 in ascending order 1 and of this we again need only the 1st column so we INDEX it and return all rows ,, and first column 1
with this formula you can add, remove or randomize your dataset and you will always get the right value for each of your rows
as for why your formula doesnt work... to not get #N/A error for vlookup you would need to define the end row of the range but still, the result wont be as you would expect coz formula is not the right one for this job.
as mentioned there are functions that are not supported under AF like SUM,AND,OR and then there are also functions which work but in a different way like IFS or with some limitations like SPLIT,GOOGLEFINANCE,etc.
I have answered you on the tab in your shared sheet called My Practice thusly:
You cannot split a two column array as you have attempted to do in cell CI2. That is why your formula does not work. You can only split a ONE column array.
I understand you are trying to learn, but attempting to use complicated formulas like that is going to make it harder I'm afraid.

Trigger IMPORTRANGE using query not working

I'm trying to use Query and IMPORTRANGE to get data from another google sheet when a checkbox in the column is TRUE. But I'm just getting an error..
Found this solution:
=QUERY(IMPORTRANGE("G-Sheet URL", "TAB & range"), "where Col15=TRUE", 1)
My code:
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o/edit#gid=0", "Spelbricka!C6:C12"), "where Col6=TRUE", 1)
It just gives me error.
Anyone?
Thanks on behalf / R
To import a range if one of your cells in that sheet is set to true, you will be wanting to set everything with an IF condition and wrap the IMPORTRANGE with an ARRAYFORMULA function. ARRAYFORMULA will let you display an array of values in differnt rows and columns rather than a single one avoiding therefore errors (as IF itself would just accept returning a single value), making your non-array function into an array function.
Moreover, with this you can also choose to return another IMPORTRANGE is the checkbox is unmarked. In the following example I'm importing a range if the cell B1 checkbox is ticked.
=(IF(B1=True,ARRAYFORMULA(IMPORTRANGE("SHEETURL","Sheet1!C6:C12")),""))
first run this in any cell and allow access:
=IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A6")
then try:
=QUERY(IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A6:E12"); "select Col3 where Col6=TRUE"; 0)
notice the range A6:E12 where we return column C only if column E equals TRUE
UPDATE:
use in C6:
=IF(
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!"&ADDRESS(MATCH(A6;
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A:A"); 0); 3))=TRUE;
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!"&ADDRESS(MATCH(A6;
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A:A"); 0); 3)&":"&ADDRESS(MATCH(A6;
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A:A"); 0)+6; 3)); )
then select C6
copy it with CTRL + C
and paste with CTRL + V into C15, C24, etc.

Cells not updating when I drag the formula down in Google Sheets

I need the cells in Payroll & Billing!B19:H19 to update as I drag to B20:H20, and so on. Please help.
=COUNTIFS(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1F59eQSqLQy9_JLfz4Rq12_pgksDSzdAM4tLkp45uaKE/edit#gid=2012166725","Payroll & Billing!B19:H19"), ">0)")
Just guessing here a bit, because the answer depends on your use case. But still.
If you need to count positive numbers row-wise from the imported range, then you could do this with MMULT and ARRAYFORMULA:
=MMULT(
ARRAYFORMULA(
--(
IMPORTRANGE(
"1F59eQSqLQy9_JLfz4Rq12_pgksDSzdAM4tLkp45uaKE",
"Payroll & Billing!B19:H20"
) > 0
)
),
SEQUENCE(2, 1, 1, 0)
)
You could just change B19:H20 in IMPORTRANGE to whatever you have in the imported sheet, and change 2 in SEQUENCE(2, 1, 1, 0) to the corresponding number of rows.
It would be really simpler to define a Named Range in your original sheet and just import that. Say, you define a Named Range for "Payroll & Billing!B19:H100" (e.g. you have the data down to 100th row) and call it My Data Range. Then you could use this:
=MMULT(
ARRAYFORMULA(
--(
IMPORTRANGE(
"1F59eQSqLQy9_JLfz4Rq12_pgksDSzdAM4tLkp45uaKE",
"My Data Range"
) > 0
)
),
SEQUENCE(
ROWS(
IMPORTRANGE(
"1F59eQSqLQy9_JLfz4Rq12_pgksDSzdAM4tLkp45uaKE",
"My Data Range"
)
), 1, 1, 0
)
)
Old answer (sorry, did not get you right the first time):
If you just need to apply this to the 19th row starting from the column B you could do this like:
=COUNTIFS(IMPORTRANGE("1F59eQSqLQy9_JLfz4Rq12_pgksDSzdAM4tLkp45uaKE","Payroll & Billing!B19:19"), ">0)")

Output multi column instead of multi row

I have had the following question, that was answered here:
Google Sheets Formula: Sum if Substring in range of cells
The final formula works and gives me a row for each month:
The question is: Once the formula is executed, it returns multiple rows- can I get the results in multiple columns? I mean, the three return values next to each other, instead of below each other?
It's the TRANSPOSE() function. To answer the original formula:
=TRANSPOSE(ARRAYFORMULA(
SUMIF(
MID(A:A, 4, 2),
UNIQUE(MID(FILTER(A3:A, A3:A <> ""), 4, 2)),
B:B
)
))
This will deliver the results in columns instead of rows.

Resources