Find names in string and combinations & lookup for value - Google Sheets - google-sheets

I've a data set with list of names & combinations and need to map with the team.
For ex, if the list of name is unique, then it should give me team name.. If the name of combination from team, it should give same team name.. Combination between two teams, then it should say team C.
Here is the trix for ref: https://docs.google.com/spreadsheets/d/1leb0hQ5gb6RclcMb__JYJLqvIFBQD_B3v7c2o4PbICg/edit#gid=0
I tried lookup, but it is fulling first case but not the people combination. Is there any way I can achieve this. Also, I assume these names are separated by ascii CHAR(10).
Let me know any inputs or suggestions so I can fulfil this.

You may use below formula-
=IFERROR(BYROW(A2:INDEX(A2:A,COUNTA(A2:A)),LAMBDA(x,UNIQUE(INDEX(XLOOKUP(FLATTEN(SPLIT(x,CHAR(10))),E2:E7,F2:F7,,0))))),"C")
Here A2:INDEX(A2:A,COUNTA(A2:A)) will return a array of values as well cell reference from A2 to last non empty cell in column A (Assume you do not have any blank rows inside data). If you have blank row, then you have to use different approach. See this post by #TheMaster
Then LAMBDA() will apply XLOOKUP() function for each cell of A column.
SPLIT() will separate all values from cell using line break CHAR(10) delimiter.
XLOOKUP() will search for name and return team.
For multiple names, UNIQUE() function will return only unique teams.
Finaly BYROW() will return that unique team. If there are more than 1 teams, then BYROW() will through error.
IFERROR() will catch that error and return C as result/exception.

You can try with this formula. It's a little long but splits the value of each cell, joins them to see if they're unique or not, and then applies C if they aren't:
=BYROW(A2:A,lambda(val,IF(val="","",lambda(results,SI(COUNTA(results)=1,results,"C"))(UNIQUE(transpose(ARRAYFORMULA(VLOOKUP (SPLIT(val,CHAR(10)),E$2:F,2,0))))))))

Related

Unnest two columns in google sheet

I have a table like this one here (basically it's data from a google form with multiple choice answers in column A and B and non-muliple choice data in column C) I need a separate row for each multiple choice answer.
Column A
Column B
Email
A,B
XX,YY
1#gmail.com
A,C
FF,DD
2#gmail.com
I tried to un-nest the first column and keep the remaining columns like this
enter image description here
I tried several approaches I found with flatten and split with array formulas but I don't know where to start really.
Any help or hint would be much appreciated!
You can use the split function on the column A and after that, use the index function. Considering the table, you can use:
=index(split(A2,","),1,1)
The split function separate the text using the delimiter indicated, returning an array with 1 line and 2 columns; the index function will return the first line and the first column from this array. To return the second element from the column A, just change to
=index(split(A2,","),1,2)
I think there's no easy solution for this. You're asking for as many combinations of elements as multiple-choice elections have been made. Any function in Google Sheets has its potentials and limitations about how many elements it can express. One very useful formula here is REDUCE. With REDUCE and sequences of elements separated by commas counted with COUNTA, you can stablish this formula:
=QUERY(REDUCE({"Col A","Col B","Email"},SEQUENCE(COUNTA(A2:A)),LAMBDA(z,c,{z;LAMBDA(ax,bx,
REDUCE({"","",""},SEQUENCE(ax),LAMBDA(w,a,
{w;
REDUCE({"","",""},SEQUENCE(bx),LAMBDA(y,b,
{y;INDEX(SPLIT(INDEX(A2:A,c),","),,a),INDEX(SPLIT(INDEX(B2:B,c),","),,b),INDEX(C2:C,c)}
))})))
(COUNTA(SPLIT(INDEX(A2:A,c),",")),COUNTA(SPLIT(INDEX(B2:B,c),",")))})),
"Where Col1 is not null",1)
Since I had to use a "initial value" in every REDUCE, I then used QUERY to filter the empty values:

Combining a Cell Reference and Wildcard as Criterion in Google Sheets CountIf Formula

I'm struggling with writing the proper syntax for this formula in Google Sheets. In one sheet called Game Log, in the H column I have data that can be a range of names (1 - 10 names per row). I'm trying to construct a COUNTIF statement that would search for the name in all the rows for that column. There can be several other names in the same column so I need to use the wildcard * to find any occurrence of the name in each row. So for example, the current code below would count all occurrence of Adam in the rows.
=COUNTIF('Game Log'!H3:H102, "*Adam*")
What I would like to do is replace the hard codes "Adam" with a cell reference (in this case B2). Is it possible to combine that cell reference with the wild card? The know the code below doesn't work (as it would return text counting occurrences of B2), but is something like this possible?
=COUNTIF('Game Log'!H3:H102, "*B2*")
Have you tried something like this?
=COUNTIF('Game Log'!H3:H102, "*" & B2 & "*")
That ought to look for any string value, followed by the cell value, followed again by any string value. It's essentially just performing separate checks, in sequence, which allows you to search for different value types (in this case string wildcard + cell value + string wildcard).

JOIN header row values across a row based on non-blank values in cells

So I have two rows:
ID
TagDog
TagCat
TagChair
TagArm
Grouped Tags (need help with this)
1
TRUE
TRUE
TagDog,TagArm
Row 1 consists mainly of Tags, while rows 2+ are entries. This data ties ENTRIES to TAGS.
What I'm needing to do is concatenate/join the tag names per entry. For example, look at the last column above.
I suspect we could write a formula that would:
Create an array of non-empty cells in the row. (IE: [2,4])
Return it with the header row A (IE: [A2,A4])
Then join them together by a comma
But I am unsure how to write the formula, or if this is even the best approach.
Here's the formula:
={
"Grouped Tags (need help with this)";
ARRAYFORMULA(
REGEXREPLACE(TRIM(
TRANSPOSE(QUERY(TRANSPOSE(
IF(NOT(B2:E11),, B1:E1)
),, COLUMNS(B1:E1)))
), "\s+", ",")
)
}
The trick used is called vertical query smash. That's the part:
TRANSPOSE(QUERY(TRANSPOSE(...),, Nnumber_of_columns))
You can find a brief description of this one and his friends here.
I wasn't able to create a single formula that would do this for me, so instead, I utilized a formula inside of Sheets' Find/Replace tool, and it worked like a charm!
I did a find/replace, replacing all instances of TRUE with the following formula:
=INDIRECT(SUBSTITUTE(LEFT(ADDRESS(ROW(),COLUMN()),3),"$","")&"$1")
What this formula does is it finds the cell's letter, then gets the first row of the cell using INDIRECT.
Breaking down the formula:
ADDRESS(ROW(),COLUMN()) returns the direct reference: $H$1
LEFT("$H$1",3) returns $H$
SUBSTITUBE("$H$","$","") replaces the dollar signs ($) and returns H
INDIRECT(H&"$1") references the exact cell H$1
Now, I can replace all instances of TRUE with that formula and the magic happens!
Here is a video explanation: https://youtu.be/SXXlv4JHDA8
Hopefully, that helps someone -- however, I would still be interested in seeing what the formula is for this solution.

Array Formula to Combine Text with Unique Condition

I have a list of customers and the products they bought.
I want to combine every product that each customer bought into respectively a single cell next to customers' name.
Is there any way with array formula that can do this? The formula is expected to be a single formula that can automatically return the value when new data is input, so I think it should be an array formula.
Here is the sample case
https://docs.google.com/spreadsheets/d/1GpCbpFz7wrZjamhtm9rHk38RgyAUCBx54BeQCIeG1H4/edit#gid=0
The expected return can be seen in E:E. But the expected formula shouldnt be like that since it is kinda painful to drag formulas all over when I input new data, it is expected to be like an array formula.
Erase contents in D:E and then enter in D1
=arrayformula(regexreplace({unique(A1:A), trim(transpose(query(if((transpose(unique(A1:A))=A1:A)*len(A1:A),B1:B&" - ",),,50000)))},"-$", ))
See if that works?

Using parts of a string to search and find a cell reference

I've been toying with a few ways to do what I want to do, so I'll start with an example of my goal:
So, in the linked sheet, I have a table with colors and animals, and then a list of entries, each with a color and animal together. My goal is this: Take the string from one of the cells in column E, i.e. E2: Red Cat, and use that information to find the associated cell, and return either the cell reference B2, or the data contained where they intersect, in this case TRUE.
I opted for the cell content rather than the cell addresses. Please try:
=OFFSET($A$1,MATCH(INDEX(split(E2," "),1),A:A,0)-1,MATCH(INDEX(split(E2," "),2),$1:$1,0)-1)
If you alter a little bit code given by #pnuts then you will get cell reference:
=ADDRESS(MATCH(INDEX(SPLIT(E2," "),1),A:A,0),MATCH(INDEX(SPLIT(E2," "),1,2),$1:1,0),4)
The last paramether could be 1-4 and the results:
$B$2
B$2
$B2
B2
also you are able to add sheet name to reference, then it would be:
=ADDRESS(MATCH(INDEX(SPLIT(E2," "),1),A:A,0),MATCH(INDEX(SPLIT(E2," "),1,2),$1:1,0),4,,"SheetName")
and the result -> SheetName!B2
Maybe a good way to automate your task is to use array formulas:
The formula is F1 to split values:
=FILTER(SPLIT(E2:E," "),E2:E<>"")
The formula in H2 to get addresses:
=FILTER(ADDRESS(MATCH(F2:F,A:A,),MATCH(G2:G,1:1,),4),E2:E<>"")
or put this in H2 to get values:
=FILTER(VLOOKUP(F2:F,A:C,MATCH(G2:G,1:1,),0),E2:E<>"")

Resources