I want to combine the content of three columns into one column like in this example:
Col1 Col2 Col3
A 1 x
B 2 Y
So the result is a column with 8 lines like this:
Result
A 1 X
A 1 Y
A 2 X
A 2 Y
B 1 X
B 1 Y
B 2 X
B 2 Y
I need a Google Sheets command to do it, not a Spreadsheet solution because the result values must change automatically when using the sheet.
I have already tried with COMBINE and JOIN without much success.
If, alternatively, you show me how to combine only two of the three columns, I then could combine the third one in a second step.
2 columns:
=ARRAYFORMULA(TRANSPOSE(SPLIT(REPT(CONCATENATE(A1:A&CHAR(9)), COUNTA(B1:B)), CHAR(9)))
&" "&TRANSPOSE(SPLIT(CONCATENATE(REPT(B1:B&CHAR(9), COUNTA(A1:A))), CHAR(9))))
3 columns:
=ARRAYFORMULA(
TRANSPOSE(SPLIT(REPT(CONCATENATE(
TRANSPOSE(SPLIT(REPT(CONCATENATE(A1:A&CHAR(9)), COUNTA(B1:B)), CHAR(9)))&" "&
TRANSPOSE(SPLIT(CONCATENATE(REPT(B1:B&CHAR(9), COUNTA(A1:A))), CHAR(9)))&CHAR(9)),
COUNTA(C1:C)),CHAR(9)))&" "&
TRANSPOSE(SPLIT(CONCATENATE(REPT(C1:C&CHAR(9), COUNTA(
TRANSPOSE(SPLIT(REPT(CONCATENATE(A1:A&CHAR(9)), COUNTA(B1:B)), CHAR(9)))&" "&
TRANSPOSE(SPLIT(CONCATENATE(REPT(B1:B&CHAR(9), COUNTA(A1:A))), CHAR(9)))))), CHAR(9))))
3 columns in two steps:
=ARRAYFORMULA(TRANSPOSE(SPLIT(REPT(CONCATENATE(D1:D&CHAR(9)), COUNTA(C1:C)), CHAR(9)))
&" "&TRANSPOSE(SPLIT(CONCATENATE(REPT(C1:C&CHAR(9), COUNTA(D1:D))), CHAR(9))))
Assuming A is in A1, in Row1 and copied down to suit:
=offset(A$1,int((row()-1)/4),)&" "&offset(B$1,abs(iseven(int((row()-1)/2))-1),)&" "&offset(C$1,mod((row()-1),2),)
Rotate, join, rotate, join then etc. There are no other ways to reach this. If I had such a task, I would try to multiply N matrices N-1 times.
=ARRAYFORMULA(TRANSPOSE(SPLIT(
TEXTJOIN("·",TRUE,SPLIT(
TEXTJOIN("·",TRUE,(A2:A3&" "&TRANSPOSE(B2:B3))),
"·")&" "&C2:C3),
"·"
)))
Related
I haven't been able to find something like this. Hoping I can get an answer in Google Sheets! I have a two columns with values pulled from the same list of 5 items. (Each row is an item that has up to two 'types' that come from a 'types list' with 5 values)
For this example:
Types
A
B
C
D
E
Example Column 1
Example Column 2
A
B
B
A
B
C
B
D
E
D
B
I want to create another table like below that will count up how many times a particular combination occurs regardless of order. Results would appear as below:
Type 1
Type 2
Count
A
B
2
B
C
1
B
E
0
D
E
1
I need this formula to count any time both values appear in either column together.
Really hoping I can get this into a simple table format, because I have another table where I will need to do similar that will be more complex so I'm hoping to avoid longer form counting tables if it can be avoided.
Any help would be much appreciated!
try:
=ARRAYFORMULA(TRIM(QUERY(IF(A:A<B:B, A:A&" "&B:B, B:B&" "&A:A),
"select Col1,count(Col1) where Col1 <> ' 'group by Col1
order by count(Col1) desc label count(Col1)''")))
Use this formula
=ArrayFormula(
{ "Type1","Type 2", "Count";
SPLIT(UNIQUE(FILTER(QUERY({IF(A2:A<B2:B, A2:A&" "&B2:B, B2:B&" "&A2:A)}), LEN(QUERY({IF(A2:A<B2:B, A2:A&" "&B2:B, B2:B&" "&A2:A)}))>2)), " "),
COUNTIF(QUERY({IF(A2:A<B2:B, A2:A&" "&B2:B, B2:B&" "&A2:A)}), "="&
UNIQUE(FILTER(QUERY({IF(A2:A<B2:B, A2:A&" "&B2:B, B2:B&" "&A2:A)}), LEN(QUERY({IF(A2:A<B2:B, A2:A&" "&B2:B, B2:B&" "&A2:A)}))>2)))})
I have 2 tables resulting from the query formulas
formula1
=query(BuchungSystem!A2:AZ,"Select C, F, H, I, J, K, L where Q = "& $B$10)
formula2
=arrayformula({{"MWST ",""}} & QUERY(query(BuchungSystem!A2:AZ,"Select M, N, L where Q = "& $B$10),"SELECT Col1*100, SUM(Col2) GROUP BY Col1, Col3 LABEL SUM(Col2) '' , Col1*100 ''"))
and the result is shown as below
I need to combine 2 ranges since the number of rows in table1 keeps changing and so in table2. Since both are query formulas, they would not expand if the underlying cells have data. To avoid such issues, I am thinking both tables can be joined together with 2 empty lines between tables.
I have tried to join the query result ranges using {formula1;formula2} but it gives me an error since both tables have differing columns. How can I merge the tables one below other?
Mind sharing an example sheet? Here is a quick example of how to include empty columns to make the ranges equal in column size.
={{QUERY(G1:K4,"SELECT G,H,I,J,K")};{"","","","",SUM(QUERY(G1:K4,"SELECT G,H,I,J,K"))}}
If you use 6 columns in one range and only 2 in the next, then you need 4 empty columns in the second {} so their sizes remain the same.
I have a Google Sheets document that looks like this:
A B C D
1
2 X X 3
3 Z Y 2
4 Z
5
How can I sum the values in column C if their corresponding values in column A are in column B?
In this case, it would be 3 + 2 because both X and Y are in column B.
Many thanks in advance!
Try:
=SUM(FILTER(C2:C,COUNTIF(B2:B,A2:A)))
Docs
SUM
FILTER
COUNTIF
I have 4 columns with values (A and C are products that mostly overlap, B and D are counts. What I'd like to do is for the values that occur in both A and C calculate the difference between B and D, and put the result in E and F.
So for example 5028421938592 count is 6 in column B and count is 2 in column D.
The result would be then be in column E: 5028421938592 and column F: 4
5028421928548 3 5028421928548 1
5028421938592 6 3259190205192 7
5028421997131 1 5028421938592 2
5028421995748 4 5028421995748 1
I suggest in E1:
=unique(query({A:B;C:D},"select Col1 where Col1 is not null order by Col1"))
and in F1 and copied down to suit:
=iferror(vlookup(E1,A:B,2,0),0)-iferror(vlookup(E1,C:D,2,0),0)
I have a table with two columns A and B the first is a tag and the second is an amount. I am trying to write a query with two columns, one summing up negative values while the other summing up positive ones.
Coming from SQL, I tried the following
=QUERY(A1:B100,
"SELECT A, SUM( B * IF(B>0, 0, 1) ),
SUM( B * IF(B<0, 0, 1) ) GROUP BY A ")
But it seems that the IF function is not supported in a query. I know I can create two intermediate columns in my sheet (one for positive value and one for negative ones), but I was wondering if it's possible to achieve what I want with a query or somehow without intermediate columns.
If you must use the query function, assuming your Tag Data is in Column A, and your Values in Column B:
=arrayformula(query({A1:A100,if(B1:B100>0,B1:B100,),if(B1:B100<0,B1:B100,)},"Select Col1, sum(Col2), sum(Col3) where Col1 <>'' group by Col1 label Col1 'Tag', sum(Col2) 'Positive', sum(Col3) 'Negative'"))
Here's the example output: https://docs.google.com/spreadsheets/d/1DW5CyPCC71CopW48uKy6basn-WP4hMfh7kuuJXT-C4o/edit#gid=1606239479
=arrayformula(query({a1:a100,if(b1:b100>0,b1:b100,),if(b1:b100<0,b1:b100,)},"Select Col1,sum(Col2),sum(Col3) group by Col1"))
Please see this sheet for an example of using the FILTER function which is probably better than your query function for this use case:
https://docs.google.com/spreadsheets/d/1DW5CyPCC71CopW48uKy6basn-WP4hMfh7kuuJXT-C4o/edit?usp=sharing
I didn't know what you meant by tag, but I just created a list of random words, 10 negative, and 10 positive
With Tags in Column A and Numbers in Column B. Then in Column D I put this for the "positive" filter:
=filter($A$2:$A,$B$2:$B>0)
And for the Positive Sum:
=sum(filter($B$3:$B,$B$3:$B>0))
And in Column E for the Negative filter:
=filter($A$2:$A,$B$2:$B<0)
And for the Negative Sum:
=sum(filter($B$3:$B,$B$3:$B<0))
EDIT: I added another sheet in the workbook that shows you how to list the sum next to each tag in a filtered list of the tags:
On this sheet, I created examples of how to list the total sums of each particular tag: https://docs.google.com/spreadsheets/d/1DW5CyPCC71CopW48uKy6basn-WP4hMfh7kuuJXT-C4o/edit#gid=1784614303
This formula will look at the list of tags/values in Columns A & B, and then match and sum all tags that are in the cell to the left in Column D:
=sum(filter($B$3:$B,$B$3:$B>0,$A$3:$A=D3))