How to combine two tables with common headers in google sheets? - google-sheets

I am trying to combine two tables with common headers. The formula below only properly works, if I define the exact start and end row. How can I adjust the formula below to dynamically fetch non blank rows from both the tables.
=iferror({A1:C50;ArrayFormula(hlookup(A1:C1,'Settings'!A1:C50,row(A2:A50),0))})
Sample Input:
Table 1
col 1
col2
col 3
abc
123
789
def
456
1212
Table 2
col 1
col2
col 3
abc
123
78849
jkl
256
1298
Desired Output:
Table 3
col 1
col2
col 3
abc
123
789
def
456
1212
abc
123
78849
jkl
256
1298

Use OUERY:
=QUERY({A1:C1;A2:C;E2:G},"WHERE Col1 IS NOT NULL")

Related

How do I sum the cells of one column based on unique duplicate rows of other columns?

I need column D summed wherever column A-C are identical. Column E is what I want the output to look like. I am only using google sheet functions right now and have not learned how to write script. This formula is the closest I've gotten.
=SUM(filter(D:D;COUNTIF(A2:A&B:B&C:C;A2:A&B:B&C:C)>1))
However, it does not distinguish between different text strings only sums any duplicate.
Thanks for any help!
A
B
C
D
E
papaya
10/10/2022
500
42
42
papaya
15/12/2022
550
30
59
papaya
15/12/2022
550
29
59
Pineapple
16/11/2022
400
55
55
Pineapple
09/11/2022
400
63
78
Pineapple
09/11/2022
400
15
78
use:
=QUERY(A:E; "select A,B,C,sum(D) where D is not null group by A,B,C label sum(D)''")
update
use in M2:
=INDEX(LAMBDA(bc; g; i; IFERROR(g/VLOOKUP(bc; QUERY({bc\i*1};
"select Col1,sum(Col2) where Col2 > 0 group by Col1 label sum(Col2)''"); 2; )))
(B2:B&C2:C; G2:G; I2:I))

Horizontal Lookup using Index Match on Google Sheets

For the following image from Google Sheets, I want to fill out column L with the value found in column A "PPID" based on values in column J "ID" and referencing the range columns B-I. For example, the value "123" should be filled out in column L for the IDs in column J that are 981296581, 682975586, etc. I tried using Index-Match formula, such as =INDEX($A$3, MATCH(J3,B3, 0)), but it only worked for the first row of data and showed an error for the remaining rows
Here is the screenshot of my Google Sheets, as well as the tables below it if you need to copy it into your Google Sheets:
SHEET 1
PPID
ID
ID
ID
ID
ID
ID
ID
ID
123
981296581
682975586
6144233
6140531
6047231
4540543
134
34
456
815220681
1532839
1141531
SHEET 2
ID
INTENDED RESULT
COLUMN TO FILL OUT (with formula)
981296581
123
682975586
123
6144233
123
6140531
123
6047231
123
4540543
123
134
123
34
123
815220681
456
1532839
456
1141531
456
Thanks!
The format isn't really conducive for a lookup. We can FLATTEN the key range and "repeat and flatten" the value range(with IF) to make it conducive for any lookup.
=ARRAYFORMULA(
XLOOKUP(
K2:K12,
FLATTEN(B2:I3),
FLATTEN(IF(COLUMN(B2:I3),A2:A3,))
)
)
ID(K1)
INTENDED RESULT
COLUMN TO FILL OUT (with formula)
981296581
123
123
682975586
123
123
6144233
123
123
6140531
123
123
6047231
123
123
4540543
123
123
134
123
123
34
123
123
815220681
456
456
1532839
456
456
1141531
456
456
try:
=INDEX(IFERROR(VLOOKUP(J3:J, IFERROR(SPLIT(FLATTEN(
IF(B3:I="",,B3:I&"×"&A3:A)), "×")), 2, 0)))
Use this
=ArrayFormula(IF(A3="",,
BYROW(B3:I3, LAMBDA(l, IF(ARRAY_CONSTRAIN(QUERY(
TRANSPOSE(REGEXMATCH(J3&"",l&"")), "Select Col1 where Col1 = TRUE"),1,1)<>TRUE,,A3)))))

How to sort data into a table from columns with duplicate names with different information for each row

So I have this data:
Name Post ID
CASTILLO, FIONA SN 32
ALDERETE, ROSABEL AN 56
ALDERETE, ROSABEL GN 11
ALMONARES, OLIVER SN 3
ALMONARES, OLIVER GN 2
ALVAREZ, JR., EDUARDO GN 36
ALVAREZ, JR., EDUARDO AN 1
ARELLANO, DONNALYN SN 36
ARELLANO, DONNALYN AN 63
ARELLANO, DONNALYN GN 7
CASTILLO, FIONA SN 1
CASTILLO, FIONA SN 1
DE LEON, AMABEL GN 1
DENNISON, GRETCHEN AN 11
DENNISON, GRETCHEN AN 26
DENNISON, GRETCHEN SN 5
And I want to create a table where the rows are the unique names of the people (not duplicated) and the column headings are Name, SN, AN, GN, and the values inside are the corresponding numbers. I know how to create this using a pivot table But which function would separate the data once the table is created.
The data above are cells A2:C16 and my desired output is C2:C9 would be the names, C1 is the name header, D1 is the SN header, E1 is the AN header, and F1 is the GN header. The values occupying the table would be the ID that corresponds with each person.
try:
=QUERY({A1:C}; "select Col1,max(Col3) where Col1 is not null group by Col1 pivot Col2")
you can change max for min, sum, avg or count if you need so

Copy over data with concatenating few columns together

In my google sheets I have two sheets/tabs.
In Sheet 1 I have below columns
A
B
C
D
1
Phone#
St Address
City
Buzzer#
2
123
Street 1
Toronto
564
3
456
Street 2
Cambridge
4
523
Street 1
Guelph
5
412
Street 1
Barrie
985
In my sheet 2 I want to copy all these data as below format. I am trying to copy over column A -> Phone# Column as is and concatenate column B | Column C | Column D columns together with ,. Where if There is Buzzer number I want to append word Buzzer end of the city name otherwise leave it blank.
A
B
1
Phone#
Complete Address
2
123
Street 1, Toronto, Buzzer 564
3
456
Street 2, Cambridge
4
523
Street 1, Guelph
5
412
Street 1, Barrie, Buzzer 985
And Here is How I have tried to copy over data from Sheet1 to sheet2 and concatenate columns B,C,D together
=Query('Sheet1'!A:D,"Select A and CONCATENATE((IF(D<>"",(CONCATENATE("Buzzer-"," ",D,", ")),"")),B,", ",C,", ",D) where A is not null",1)
Obviously this didn't work.
Any suggestions or Help please?
I've made a quick sheet with the solution using:
=ARRAYFORMULA(IF(ISBLANK(Sheet1!A2:A12), "",ARRAYFORMULA({Sheet1!A2:A12,ARRAYFORMULA(Sheet1!B2:B12&", "&Sheet1!C2:C12&", "&Sheet1!D2:D12)})))
The sheet:
https://docs.google.com/spreadsheets/d/1E1lBW63CyVJAUmq1okIQgn6-FY82QHt829hpeb0yWxw/edit?usp=sharing

Get Max value from range (multiple sheets) grouped by Name

I have 3 sheets that have the exact same format
Sheet1
A B C D
George 10 2 8
Nick 15 89 0
Mike 13 1 50
Lucas 9 -5 12
Sheet2
A B C D
Nick 1 9 5
Mike 1 10 6
George 11 22 5
Lucas 10 5 2
Panos 55 0 1
Sheet3
A B C D
Panos 0 9 1
George 1 2 5
Nick 7 2 1
Lucas 1 5 1
I want to query the range {'Sheet1'!A1:D5; 'Sheet2'!A1:D5; 'Sheet3'!A1:D5}
And get something like MAX(Col2:Col4) Group By Col1
Which would return something like:
George 22
Nick 89
Mike 50
Lucas 12
Panos 55
I tried:
=sort(query({'Sheet1'!A1:D5; 'Sheet2'!A1:D5;'Sheet3'!A1:D5}, "select Col1, MAX(Col2:Col4) Group by Col1 Label MAX(Col2:Col4) '' " ),2, FALSE)
and
=sort(query({'Sheet1'!A1:D5; 'Sheet2'!A1:D5;'Sheet3'!A1:D5}, "select Col1, MAX(MAX(Col2),MAX(Col3), MAX(Col4)) Group by Col1 " ),2, FALSE)
Both didn't work. Any ideas?
Please try:
=query(sort(transpose(query({Sheet1!A1:D5;Sheet2!A1:D5;Sheet3!A1:D5},"select max(Col2), max(Col3), max(Col4) pivot Col1"))),"select Col1, max(Col2) group by Col1 label(Col1) ''")
To sum up your question, It requires finding the MAX across the columns to the right as well as down. As such, QUERY does NOT have such 2D function.
So, Use a Helper column E&F in each sheet:
Max of B&C:
E2:
=ARRAYFORMULA(IF(B2:B>C2:C,B2:B,C2:C))
Max of B,C&D:
F2:
=ARRAYFORMULA(IF(D2:D>E2:E,D2:D,E2:E))
Now, Use Query:
Query:
=ARRAYFORMULA(QUERY({Sheet1!A2:F;Sheet2!A2:F;Sheet3!A2:F}, "Select Col1,max(Col5) where Col1 is not null group by Col1 order by max(Col5) desc"))
Notes:
Change ranges to suit
You could also simply use MAX for each row without the ARRAYFORMULA
Theoretically, For a single cell solution, You could enter this formula to find the max of 3 real numbers
Another approach perhaps a bit simpler but needing two queries
=sort(unique(({Sheet1!A1:A5;Sheet2!A1:A5;Sheet3!A1:A5})))
to get the names starting in (say) F2
Then this to get the maximum values for each name in (say) G2 and pulled down
max(query({Sheet1!A$1:D$5;Sheet2!A$1:D$5;Sheet3!A$1:D$5},"select max(Col2),max(Col3),max(Col4) where Col1='"&F2&"'"))

Resources