Given two tables like those above. The first one contains the data that should be filtered as a single string in the second one.
1st table
A
B
C
D
E
...
M
1st row
Tese
1
Tema
3
Vinculo
...
221
2nd row
Tese
2
Tema
5
Sem
...
443
3rd row
Tese
5
Tema
9
Vínculo
...
221
4th row
Tese
7
Vinculo
...
221
2nd table
A
B
1st row
221
Tese 1>Tema 3>Vínculo>Tese 5>Tema 9>Vinculo>Tese 7>Vinculo
2nd row
443
Tese 2>Tema 5>Sem
Also, as the table is huge, I need an array formula or a query...
Is there hope for me?
Link to the actual table here
It's technically possible to do it all in one Arrayformula, but I would not recommend it and do not have the ability to answer follow up questions. See this sample sheet.
=ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(TRIM(QUERY(MID(QUERY(SPLIT(FLATTEN("00000_"&Data!M2:M&"#|"&TEXT(ROW(Data!A2:A)*10+{1,2,3},"00000")&"_>"&{Data!A2:A&" "&Data!B2:B,Data!C2:C&" "&Data!D2:D,Data!E2:E}),"|",0,0),"select MAX(Col2) where not Col2 ends with ' ' group by Col2 pivot Col1"),7,1000),,9^9))),"# >",0),"offset 1",0))
You need multiple query statements for each unique value in column M:
So in the first column (assuming this is a different sheet) use:
=UNIQUE(Sheet1!M1:M)
Then on the second column use:
=TEXTJOIN(">",TRUE,TRANSPOSE(FLATTEN(QUERY(Sheet1!$A$1:$M,"select A,B,C,D,E where M = "&$A1))))
Since ARRAYFORMULA does not support multiple query statements on different conditions, you need to drag down or use autofill.
Sample:
Related
Would it be possible to use arrayformular for this condition?
Sum all the rows that PID are the same, the result should be as in the image.
I tried this code, but I think it's too long, and if the PID exceed over 20 rows, it would not work.
=IF(A3<>A2,BJ3+IF(A3=A4,BJ4,0)+IF(A3=A5,BJ5,0)+IF(A3=A6,BJ6,0)+IF(A3=A7,BJ7,0)+IF(A3=A8,BJ8,0)+IF(A3=A9,BJ9,0)+IF(A3=A10,BJ10,0)+IF(A3=A11,BJ11,0)+IF(A3=A12,BJ12,0)+IF(A3=A13,BJ13,0)+IF(A3=A14,BJ14,0)+IF(A3=A15,BJ15,0)+IF(A3=A16,BJ16,0)+IF(A3=A17,BJ17,0)+IF(A3=A18,BJ18,0)+IF(A3=A19,BJ19,0)+IF(A3=A20,BJ20,0)+IF(A3=A21,BJ21,0)+IF(A3=A22,BJ22,0),0)
With a table like this :
ID
Value
1
5
1
10
2
5
2
10
2
15
You have an expected output of :
ID
Value
Sum
1
5
15
1
10
blank
2
5
30
2
10
blank
2
15
blank
It is achievable with this formula (just drag it in your sum column) :
=IF(A2=A1,"",SUMIFS(B$2:B$12,A$2:A$12,A2))
It check if the ids are the same and then sum them, but only show them on the row where the id first appears
Found it on google by searching google sheets sum group by
The following in C2 will generate the required answer without any copying-down required:
=arrayformula(if(len(A2:A),ifna(vlookup(row(A2:A),query({row(A2:B),A2:B},"select min(Col1),sum(Col3) where Col2 is not null group by Col2"),2,false)),))
We are making a lookup table of grouped sums against the first row of each 'P#' group using QUERY, then using VLOOKUP to distribute the group sums to the first row in each group. Probably also doable using a SCAN/OFFSET combination as well, I think.
I am trying to do the full join for the data below in two different sheets.
Sheet 9:
Product ID
Name
Quantity
1
addi
55
2
fadi
66
3
sadi
33
Sheet10
Product ID
Variants
Model
1
xyz
2000
2
differ
2001
3
saddd
336
4
fsdfe
2005
Desired output sheet :
Product ID
Name
Quantity
Variants
Model
1
addi
55
xyz
2000
2
fadi
66
differ
2001
3
sadi
33
saddd
336
4
fsdfe
2005
Please also share if we have more columns to join like in sheet 1 and sheet 2 has two more columns like Year, product label etc then what should I change in your proposed solution
I am using this formula but its not returning the desired result
=ARRAYFORMULA({QUERY(SORT(UNIQUE({Sheet9!A1:D; Sheet10!A1:D})), "where Col1 is not null"),IFERROR(VLOOKUP(TRANSPOSE(QUERY(TRANSPOSE(QUERY(SORT(UNIQUE({Sheet9!A1:D; Sheet10!A1:D})), "where Col1 is not null")),,999^99)), TRANSPOSE(QUERY(TRANSPOSE(Sheet9!A1:D),,999^99)), Sheet9!C1:C}, 2, 0),""),IFERROR(VLOOKUP(TRANSPOSE(QUERY(TRANSPOSE(QUERY(SORT(UNIQUE({Sheet9!A1:D; Sheet10!A1:D})), "where Col1 is not null")),,999^99)), {TRANSPOSE(QUERY(TRANSPOSE(Sheet10!A1:D),,999^99)), Sheet10!C1:C}, 2, 0),"")}})
EDITED to consider dynamic row matching.
See this spreadsheet to illustration, but overall there's a question of your setup, but I would break your problem into two steps.
Get distinct list of ID's
You can get that with this formula:
=unique(transpose(split(textjoin(",",true,
iferror(INdex(Sheet2!$A$2:$Z,0,MATCH(A1,Sheet2!1:1,0)),""),
iferror(INdex(Sheet1!$A$2:$Z,0,MATCH(A1,Sheet1!1:1,0)),"")),",")))
Rest of Headers
Then for each header, will they each always only be in 1 exclusively or 2 (not both)? Assuming so, this should work for each additional column. If two values ever exist in the two sheets, will join them in the same column.
=filter(
iferror(VLOOKUP($A$2:$A,Sheet1!$A:$Z,match(E$1,Sheet1!1:1,0),false),"")
&iferror(VLOOKUP($A$2:$A,Sheet2!$A:$Z,match(E$1,Sheet2!1:1,0),false),"")
,$A$2:$A<>"")
There's probably a way to use the join function to do this more elegantly (if someone posts an answer showing me I'll upvote).
A B C
1 4 Apple
2 5 Orange
3 6 Apple
1 4 Orange
2 4 Apple
3 4 Banana
I want to count each type of column C(if possible also plot it), ie output should be
Apple 3
Orange 2
Banana 1
Just more to a new columns and paste the folloing in its header:
=query(H2:H,"select H, count(H) where H != '' group by H order by count(H) desc label H 'Fruit'", 0)
It is show something like your expection in new two columns beside the original data
As an alternative to the solution already provided, you can make use of UNIQUE and COUNTIF.
Use UNIQUE in order to extract the names for each fruit from the C column
=UNIQUE(C1:C)
Use COUNTIF within an ARRAYFORMULA in order to count the number of times each fruit is present in the C column and later drag it down the E column:
=ARRAYFORMULA(COUNTIF(C1:C,D1))
Reference
UNIQUE Function;
COUNTIF Function.
Given a column of data here:
13
4
76
8
56
4
7
3
Is there a way to use MATCH() function (or similar) such that it will return the row number of the last blank or non-numeric row it finds? I will accept any solution that can search for either blank of non-numeric
=MATCH("", A:A) returns #N/A instead of 8
If not, is there a way to achieve this without using a script?
Usage:
I'm essentially looking for a way to create a range from the last blank cell to the current row.
Solution
Last row number
=MAX(QUERY({ARRAYFORMULA(ROW($A:$A)),$A:$A},"select Col1 where Col2 is null"))
Range from current row to last empty row (in A column) - you may put this everywhere except col A:
=ADDRESS(ROW(),COLUMN(),4)&":"&ADDRESS(MAX(QUERY({ARRAYFORMULA(ROW($A:$A)),$A:$A},"select Col1 where Col2 is null")),COLUMN(),4)
Img
Is that what you where trying to get?
I have columns like the left two below, but want columns like the right two. I'm not sure if there is even a name for this transformation, or what it is. Query with Group By seems the closest I could find, but wants to aggregate the data items rather than listing them in each group. The left columns would be created by merging various data entry sheets, reordering columns, and sorting by column A. I've got that figured out. But converting to the format in columns C & D baffles me. I guess it is more of a report-writer function: do I need to write a script function with a loop to achieve this result, or is there something I am overlooking?
A B C D
A group - subgroup1 data 1 A group - subgroup1
A group - subgroup1 data 2 data 1
A group - subgroup1 data 3 data 2
A group - subgroup2 data 4 data 3
A group - subgroup2 data 5 A group - subgroup2
A group - subgroup2 data 6 data 4
A group - subgroup2 data 7 data 5
B group - subgroup1 data 8 data 6
B group - subgroup1 data 9 data 7
C group - subgroup1 data 10 B group - subgroup1
C group - subgroup1 data 11 data 8
C group - subgroup3 data 12 data 9
C group - subgroup3 data 13 C group - subgroup1
C group - subgroup3 data 14 data 10
data 11
C group - subgroup3
data 12
data 13
data 14
As #ttarchala suggested, Pivot tables is a useful functionality. I did try to make a query solution though. It's NOT exactly what you wanted. But, it's close, IMO:
=ARRAYFORMULA(SPLIT(TRANSPOSE(QUERY(QUERY(A2:B15,"select max(B) group by B pivot A")&"🐓",, 999999999999))&" ", "🐓 ", 0))
The idea here is to fake a aggregation function like MAX, So that we can pivot inside query. The rest of the formula is simply to remove blanks.
You may want to use a pivot table. Define columns A and B as dimensions of the pivot table, then put both of them on the left (vertical) axis.
This will not achieve exactly what you want - headings will not be on a separate line - but will enable useful things like automatic recalculation and subtotals.
Thanks to proposed answers by https://stackoverflow.com/users/34704/ttarchala and https://stackoverflow.com/users/8404453/i-i I was able to come up with the exact formulas needed, although it took two steps.
The data was in Column A & B, I wanted the results in C & D, so I put the temporary results in E & F. So the first formula goes in E1, and the second in C1.
=ARRAYFORMULA(split(Transpose(split(Textjoin("█",TRUE,Transpose(QUERY({A1:A14&"¤␣","␣¤"&B1:B14},"select max(Col2) group by Col2 pivot Col1"))),"█")),"¤"))
=Arrayformula(if(E:F="␣","",E:F))
The pivot table was helpful. I preprocessed my two columns of data so that header column had a trailing ¤␣ and the data a leading ␣¤. Then after the Transpose(split(Textjoin(Transpose))) stuff, I wound up with a single column that I could split on ¤ and get two columns, with the desired-to-be-blank cells containing ␣. The second pass (because I couldn't figure out how to join the formulas) was to replace the ␣ with nothingness into the result columns.