lookup value in google sheets - google-sheets

I need some help with google sheets lookup. I tried using VLOOKUP to do this, but wasn’t successful. I’m a google sheets beginner so need some help getting started.
I have 2 google sheets.
This is sheet1
Name
Emma
Kate
Tori
Rick
Jack
Topp
Brit
This is sheet2
Level1 Level2 Level3 State City
Brit Tori Kate Florida Orlando
Brit Tori Rick Alabama Gunther
Brit Topp Rick Texas Dallas
Jack Emma Rick Ohio Dayton
Jack Emma Rick Utah Puntin
Jack Emma Rick Maine Lunop
I want to add 2 columns to sheet1 so that it looks like this.
Name State City
Emma Ohio, Utah, Maine Dayton, Puntin, Lunop
Kate Florida Orlando
Tori Florida, Alabama, Texas Orlando, Gunther, Dallas
…and so on for the rest.
Rick
Jack
Topp
Brit

use:
=ARRAYFORMULA(IFNA(REGEXREPLACE({
VLOOKUP(A2:A, TRIM(SPLIT(FLATTEN(QUERY(QUERY(SPLIT(FLATTEN(
SEQUENCE(COUNTA(E2:E), COUNTA(E2:G))&"×"&E2:G&"♥×"&H2:H&","), "×"),
"select max(Col3) where Col2 is not null
group by Col1 pivot Col2"),,9^9)), "♥")), 2, 0),
VLOOKUP(A2:A, TRIM(SPLIT(FLATTEN(QUERY(QUERY(SPLIT(FLATTEN(
SEQUENCE(COUNTA(E2:E), COUNTA(E2:G))&"×"&E2:G&"♥×"&I2:I&","), "×"),
"select max(Col3) where Col2 is not null
group by Col1 pivot Col2"),,9^9)), "♥")), 2, 0)}, ",$", )))

For State column use-
=JOIN(", ",FILTER(Sheet2!D$2:D,MMULT(--(Sheet2!$A$2:$D=$A2),SEQUENCE(COLUMNS(Sheet2!$A$2:$D$2)))))
Then drag down and across as needed.

Related

Sorting information in Google Sheets

I have some information in Google Sheets in the following format:
Authors
Number
Akwaeke Emezi
2
Ezra Claytan Daniels, Ben Passmore
3
Nick Tapalansky, Kate Glasheen
9
John Allison, Lissa Treiman, Whitney Cogar
1
John Allison, Lissa Treiman, Max Sarin, Whitney Cogar
2
Gene Luen Yang, Sonny Liew
43
Gene Luen Yang
9
I would like to have a second sheet that does the following:
Generate a list of each individual author in "Authors" (ideally in alphabetical order by last name)
Calculate the average Number associated with each author (e.g. Akwaeke Emezi would be 2 and Gene Luen Yang would be (43+9)/2)
I can do this as a one-off calculation, but what I'm really looking for is a way to set this up such that when I add more entries to the spreadsheet (where the new entries will contain a combination of new authors and authors that already appear in the list), this second sheet will automatically update the list of individual authors and their associated average numbers.
try:
=ARRAYFORMULA(QUERY(QUERY(SPLIT(FLATTEN(REGEXEXTRACT(
SPLIT(A2:A, ","), " (.*)$")&"×"&TRIM(SPLIT(A2:A, ","))&"×"&B2:B), "×"),
"select Col1,Col2,sum(Col3)/count(Col2) where Col3>0 group by Col1,Col2"),
"select Col2,Col3 offset 1", 0))
or:
=ARRAYFORMULA(QUERY(QUERY(SPLIT(FLATTEN(REGEXEXTRACT(
SPLIT(A2:A, ","), " (\w+)$")&"×"&TRIM(SPLIT(A2:A, ","))&"×"&B2:B), "×"),
"select Col1,Col2,sum(Col3)/count(Col2) where Col3>0 group by Col1,Col2"),
"select Col2,Col3 offset 1", 0))
update:
=ARRAYFORMULA(QUERY(QUERY(SPLIT(FLATTEN(REGEXEXTRACT(
TRIM(SPLIT(REGEXREPLACE(A2:A,
"\b(?:X)?(?:X)?(?:X)?(?:V)?(?:I)?(?:I)?(?:I)?(?:V)?(?:X)?(?:X)?(?:X)?\b", ), ",")),
" (\w+)$")&"×"&TRIM(SPLIT(A2:A, ","))&"×"&B2:B), "×"),
"select Col1,Col2,sum(Col3)/count(Col2) where Col3>0 group by Col1,Col2"),
"select Col2,Col3 offset 1", 0))

How to extract unique rows based on a criteria across different sheets on Google Sheets

I have a main sheet with a lot of data but here it is simplified:
Manager
Employee
Project
Date
John
James
Pineapple
1/1/2021
John
James
Banana
1/1/2021
Alex
Robert
Apple
1/1/2021
Sally
Mindy
Kiwi
2/1/2021
Sally
Mindy
Orange
1/1/2021
Sally
Matthew
Tomato
2/30/2021
Sally
Mindy
Grape
1/1/2021
John
Vlad
Orange
2/30/2021
I tried using a formula that looks like this:
=ARRAYFORMULA(INDEX($B$2:$B,SMALL(IF($A$2:$A=B$1,ROW($A$2:$A)-MIN(ROW($A$2:$A))+1,""),ROW(B2))))
However it's not working.
I got the =UNIQUE() for each person from column A:
UNIQUE
John
Alex
Sally
I transpose this into their own columns:
John
Alex
Sally
and then I want a formula under each name that will go through the range that I specify
John
=UNIQUE() for column B "Employee" based on the criteria "John" in column A
=COUNTIF()
James
2
Vlad
1
And this would be useful to figure out the projects based on the criteria of column A "Manager"
John
=UNIQUE() Column C "Project"
=COUNTIF()
Pineapple
1
Banana
1
Orange
1
What's the best way of organizing this?
try:
=QUERY({A2:C}, "select Col3,count(Col2) where Col3 is not null group by Col3 pivot Col1")

Use COL name to Get ROW names based on whether a value exists in a Column with the specified Name

Would deeply appreciate it if anyone could help me with this.
Overview
In a google sheet I have the following grid:
School A
School B
School C
Tim
x
x
John
Martin
x
x
Jack
x
The Rows are Names of people who cater to certain schools. The value 'x' in the cell simply signifies the relation. So Tim caters to School A & School C and similarly Jack only caters to School C.
Note: The cells are either empty or contain that 'x'. Thought that might help. We don't really need to look for 'x' just a non-empty cell.
Question
I have another table like follows, where I have a School column listing all the schools in rows. I would like to create a formula to use the table above and return a concatenated string listing all the people catering to that school.
School
People
School A
Tim, Martin
School B
Martin
School C
Tim, Jack
use:
=INDEX(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(TRANSPOSE(QUERY(QUERY(SPLIT(FLATTEN(
IF(B2:D="",,B1:D1&"♠♦"&A2:A&",♦"&A2:A)), "♦"),
"select Col1,max(Col2) where Col2 is not nUll group by Col1 pivot Col3"),
"offset 1", 0)),,9^9)), "♠")), ",$", ))
or:
=INDEX(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(
{B1:D1&"♦"; IF(B2:D="",,A2:A&",")},,9^9)), "♦")), ",$", ))

Is there a way to use COUNTIF in Google Sheet to compare the occurrences of a value in ODD or EVEN increments for an inventory loan IN and OUT sheet

I am trying to use a Google Sheet to monitor the loan of inventory IN and OUT. There are several item numbers involved. There are two named ranges: ITEMIN and ITEMOUT. I tried using this formula:
=IF(ISBLANK(ITEMOUT),"--N/A--", IF(COUNTIF(ITEMIN, ITEMOUT)=0,"IN", "OUT"))
but it only registers correctly for the first cycle. Subsequent loan outs will be registered as IN. I have then tried this formula:
=IF(ISBLANK(ITEMOUT),"--N/A--", IF(ISODD(COUNTIF(ITEMIN,ITEMOUT)), "IN", "OUT"))
I tried to capture the ODD and EVEN occurrences of the item numbers to register the OUT and IN. For example: 1 occurrence (odd) of item no. 168 = OUT, 2 occurrences (even) of item no. 168 = IN and so on. The latter formula registered the OUT and IN in the following order for a particular item number: OUT->IN->IN->OUT->OUT->IN->IN instead of OUT->IN->OUT->IN
Really hope someone can help me with this as I am not really proficient in formulas or scripts.
Thank you in advance.
Actual worksheet:
Desired worksheet:
*NOTE: Attention to the item number 160 for both images.
based on your sheet this is the IN/OUT:
=ARRAYFORMULA({QUERY(SPLIT(FLATTEN({
IF('CHECK OUT'!C2:H="",,'CHECK OUT'!A2:A&"×"&'CHECK OUT'!B2:B&"♦"&'CHECK OUT'!C2:H);
IF('CHECK IN'!C2:H="" ,,'CHECK IN'!A2:A &"×"&'CHECK IN'!B2:B &"♦"&'CHECK IN'!C2:H)}), "×"),
"select Col2 where Col2 is not null order by Col1"), IF(ISODD(COUNTIFS(QUERY(SPLIT(FLATTEN({
IF('CHECK OUT'!C2:H="",,'CHECK OUT'!A2:A&"×"&'CHECK OUT'!B2:B&"♦"&'CHECK OUT'!C2:H);
IF('CHECK IN'!C2:H="" ,,'CHECK IN'!A2:A &"×"&'CHECK IN'!B2:B &"♦"&'CHECK IN'!C2:H)}), "×"),
"select Col2 where Col2 is not null order by Col1"), QUERY(SPLIT(FLATTEN({
IF('CHECK OUT'!C2:H="",,'CHECK OUT'!A2:A&"×"&'CHECK OUT'!B2:B&"♦"&'CHECK OUT'!C2:H);
IF('CHECK IN'!C2:H="" ,,'CHECK IN'!A2:A &"×"&'CHECK IN'!B2:B &"♦"&'CHECK IN'!C2:H)}), "×"),
"select Col2 where Col2 is not null order by Col1"),
SEQUENCE(COUNTIF({'CHECK OUT'!C2:H; 'CHECK IN'!C2:H}, "<>")), "<="&
SEQUENCE(COUNTIF({'CHECK OUT'!C2:H; 'CHECK IN'!C2:H}, "<>")))), "IN", "OUT")})

How can I get a QUERY to CONCATENATE text after it combines data?

On this sheet, I've been working on I have the info I need adjusting down into the Query Results
=QUERY(Investors!A4:D,
"select B,C,sum(D)
where B is not null
group by B,C
label sum(D)''")
How do I get the Stock Numbers Due that day to be listed out in column D? Like this:
1. 10/7/2019 Grady Johnson $100.12 PT-1013
2. 11/15/2020 Bill Jones $553.80 PT-1020, PT-1019
3. 11/15/2020 Grady Johnson $45.00 PT-1011
4. 11/15/2020 Steve Robinson $320.00 PT-1018, PT-1016
5. 11/17/2020 Jim Luke $1,057.20 PT-1009, PT-1008, PT-1007, PT-1006
6. 11/22/2020 Jim Luke $300.43 PT-1010
Here's the link: Google Sheet
Any help is appreciated!
or paste this in row 3 and drag down:
=JOIN(", ", IFNA(FILTER(Investors!A$4:A, Investors!B$4:B&" "&Investors!C$4:C=A3&" "&B3)))
try:
=ARRAYFORMULA(REGEXREPLACE(IFNA(VLOOKUP(TO_TEXT(A3:A)&" "&B3:B,
TRIM({TRANSPOSE(QUERY(TRANSPOSE(QUERY(QUERY({Investors!A4:C},
"select Col2,Col3,count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"select Col1,Col2 offset 1", 0)),,9^9)),
TRANSPOSE(QUERY(TRANSPOSE(IF(QUERY(QUERY({Investors!A4:C},
"select count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"offset 1", 0)="",,
QUERY(QUERY({Investors!A4:A&",", Investors!B4:C},
"select count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"limit 0", 1))),,9^9))}), 2, 0)), ",$", ))
Here is my suggested formula to be placed in Combined!D3 of your sample spreadsheet:
=ArrayFormula(IF(A3:A="",,SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(VLOOKUP(TRANSPOSE(FILTER(Investors!A4:A,Investors!A4:A<>"")),{Investors!A:A,Investors!C:C&Investors!B:B},2,FALSE)=B3:B&A3:A,TRANSPOSE(FILTER(Investors!A4:A,Investors!A4:A<>"")),))," ",COUNTA(Investors!A4:A))))," ",", ")))
As for how it works, that would be time-consuming to explain. (More time than is reasonable for a free site such as this.) I will suggest that, if this is important to you, take the time to study it. Take it apart and see what each piece does — separately and then in combination with other parts — until you've gotten it all back together.

Resources