Combining hlookup and vlookup - google-sheets

I am trying to import some data from one sheet to another using lookups.
I have one sheet with some data including date, name, and type of data(Puschases, Shops).
https://docs.google.com/spreadsheets/d/1sg3fh3giXlEg1SePkwZhO_RTUEPN8WBsmAJLWSKbpkA/edit#gid=0
I then have another sheet for each team member. I want the purchases and shops data(from sample data sheet) to import to their sheet by name, date, and type of data.
https://docs.google.com/spreadsheets/d/1of3wCGMZ_JEZpcxvo98Riluc5OJROMLfUN9S9LIkicE/edit#gid=0
Any thoughts on how to do this? Any help would be appreaciated.

try:
=ARRAYFORMULA(IFNA(VLOOKUP(B2:B, QUERY(
IMPORTRANGE("1sg3fh3giXlEg1SePkwZhO_RTUEPN8WBsmAJLWSKbpkA", "Sheet1!B1:I"),
"select Col8,max(Col3) group by Col8 pivot Col1", 1), {3, 4}, 0)))
UPDATE:
=ARRAYFORMULA(IFNA(VLOOKUP(B2:B, QUERY(
IMPORTRANGE("1sg3fh3giXlEg1SePkwZhO_RTUEPN8WBsmAJLWSKbpkA", "Sheet1!B1:I"),
"select Col8,max(Col"&MATCH(A2,
IMPORTRANGE("1sg3fh3giXlEg1SePkwZhO_RTUEPN8WBsmAJLWSKbpkA", "Sheet1!B1:I1"), 0)&")
group by Col8 pivot Col1", 1), {3, 4}, 0)))

Related

how to import rows that contain the same value more than once to another sheet

I have a list of sessions, I want to be able to import the ones that have been rescheduled (along with the new rescheduled session) to another sheet. So under colC one will say 'Rescheduled' and the other will say 'Attended'. So what I'd like to do is grab the participant name, but only if it shows up more than once, so I'd get both the rescheduled session and the new session. I tried using importrange and query, but couldn't quite get it right. How can I do this?
https://docs.google.com/spreadsheets/d/10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc/edit?usp=sharing
try:
=INDEX(REGEXEXTRACT(FLATTEN(QUERY(QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY({
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C"),
FLATTEN(QUERY(TRANSPOSE(
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C")),,9^9))},
"select max(Col4) where Col1 is not null group by Col2 pivot Col3")),
"where Col1 matches 'Rescheduled|Attended'", )),
"where Col1 is not null and Col2 is not null"),
"offset 1", )),
"(\d+/\d+/\d+) (.*) (Att.*|Res.*)"))
Formula Explanation:
Take the IMPORTRANGE
Merge all columns into one column
Create a virtual array {}
Pass into QUERY and pivot the data
Transpose the result
Use query to get only needed columns
Transpose back
Compare 1st and 2nd columns and remove
Remove header row
Flatten data into one column and split into the 3 needed columns
and if that's not enough:
=INDEX(REGEXREPLACE(SORT(TEXT(REGEXEXTRACT(FLATTEN(
QUERY(QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY({
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C"),
FLATTEN(QUERY(TRANSPOSE(
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C")),,9^9))},
"select max(Col4) where Col1 is not null group by Col2 pivot Col3")),
"where Col1 matches 'Rescheduled|Attended'", )),
"where Col1 is not null and Col2 is not null"),
"offset 1", )),
"(\d+/\d+/\d+) (.*) (Att.*|Res.*)"), {
"yyyymmdd\×m/d/yyyy", "#", "#"}), 2, 0, 1, 1), "^(\d+×)", ))
demo sheet

Returning top value of column from range in google sheets

Say I had a list like this.
Group 1 Group 2
Edward, C Kate, A
Mark, F Ava, Z
Now, in a different column =IF(COUNTIF('Gender'!$A$2:$B$3, "Kate, A"), "", "") is my current formula. I would like to make the first set of empty speech marks return Group 1 or Group 2 depending what column it is. I still require the COUNTIF because my actual sheet has values which will not be contained in either column.
Thanks.
try:
=INDEX(IFNA(VLOOKUP("Kate, A", SPLIT(FLATTEN(
IF(Gender!A2:B="",,Gender!A2:B&"×"&Gender!A1:B1)), "×"), 2, 0)))
update:
=INDEX(IFNA(VLOOKUP(A1:A, QUERY(SPLIT(FLATTEN(
IF(Groups!B2:C="",,Groups!B2:C&"×"&Groups!A1&"×"&Groups!B1:C1),
IF(Groups!F2:G="",,Groups!F2:G&"×"&Groups!E1&"×"&Groups!F1:G1)), "×"),
"select Col1,max(Col3) where Col2 is not null
group by Col1 pivot Col2 label Col1'"&A1&"'"), {2, 3}, 0)))
demo sheet

Lookups in Google Sheets

I am trying to use a sort of lookup to carry some data across from one sheet to the next. I have a form responses sheet collecting subjects a student would like to choose and from this, I have worked out how to split these choices into separate columns.
I then need this data taken to a second sheet where the split subjects are matched to the identical headings and a Y is put in the corresponding column for each corresponding student.
Is this possible?
try:
=ARRAYFORMULA(SUBSTITUTE(IFERROR(HLOOKUP(C1:1, IFNA(VLOOKUP(A1:A,
QUERY(SPLIT(FLATTEN({'Form Responses 1'!B2:B&"×"&
IFERROR(SPLIT('Form Responses 1'!C2:C, ", ", ))}), "×"),
"select Col1,count(Col1) where Col2 is not null group by Col1 pivot Col2 label Col1 'Email'"),
SEQUENCE(1, 1+COUNTUNIQUE(FLATTEN(SPLIT(TEXTJOIN(", ", 1, 'Form Responses 1'!C2:C), ", ", )))), 0)),
IF(A2:A="",,ROW(A2:A)), 0)), 1, "Y"))

Is there any option to display the values from another sheet?

i want to display the value in another sheet by a solution. so that when we enter a code it must search from the last sheet and generate value. pls check
should be:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A10, QUERY(
{'Please Solve'!$A$2:$B$10;'Please Solve'!$C$2:$D$10},
"select Col1,Col2 where Col1 <>'' order by Col1,Col2 ", 0), 2, 0)))

Formula to fill a two dimensional grid with computed value from a table

Here is a problem to solve with a Google Sheets formula.
I have a big table (sheet “data” with headers on the first row) with those columns:
A, product reference
B: customer
C to F, KPI1 to KPI4
On another sheet, a grid of product references (A2:A) by customer (B1:1).
Now I need to fill each cell from the grid with the concatenation of KPIs (data!C24&"|"&data!D24&"|"&data!E24&"|"&data!F24)
Could you workout a single formula to fill all the cells?
Here is a sample spreadsheet with the data and grid sheet:
https://docs.google.com/spreadsheets/d/1iA_kw4kKw99Qk69X4tST9U-QN2SeG2EN3KEeyG6AtHs/edit?usp=sharing
I have worked out a formula which does the job, though with very poor performance on large dataset:
=ARRAYFORMULA(
IFNA(
VLOOKUP(
$B3:$B&"|"&C$2:$2,
ARRAYFORMULA(
{data!A2:A&"|"&data!B2:B,data!C2:C&"|"&data!D2:D&"|"&data!E2:E&"|"&data!F2:F}
),2,0
),""
)
)
Solution
Use an ArrayFormula on a Query with Pivot:
=ARRAYFORMULA(
QUERY(
{data!A2:A, data!B2:B, data!C2:C&"|"&data!D2:D&"|"&data!E2:E&"|"&data!F2:F},
"select Col1,max(Col3) where Col1 is not null group by Col1 pivot Col2",0
)
)
a shorter version of previous answer (no need for pre-sorting coz pivot will sort it on its own):
=ARRAYFORMULA(QUERY(
{data!A2:A, data!B2:B, data!C2:C&"|"&data!D2:D&"|"&data!E2:E&"|"&data!F2:F},
"select Col1,max(Col3) where Col1 is not null group by Col1 pivot Col2", 0))
Try this on the first cell of your grid:
=ArrayFormula(query(sort({data!A:A,data!B:B,transpose(substitute(query(transpose(data!C:F),,4)," ","|"))},1,true,2,true),"select Col1, max(Col3) where Col1 is not null group by Col1 pivot Col2",0))

Resources