When I use IF it works perfectly.
=IF(H6="Vaga", QUERY(A2:D60, "SELECT * WHERE A "&H3&"
"&H9&"'"),QUERY(A2:D60, "SELECT * WHERE C "&H3&" '"&H9&"'"))
But when I try IFS, it says there is an error with number of rows and columns
=IFS(H6="Vaga", QUERY(A2:D60, "SELECT * WHERE A "&H3&" '"&H9&"'"),
H6="Empresa", QUERY(A2:D60, "SELECT * WHERE C "&H3&" '"&H9&"'"),
H6="Postada", QUERY(A2:D60, "SELECT * WHERE E "&H3&" '"&H9&"'"))
I don't know why it's not working, but IFS has some limitations with arrays and likely with query. However an easy solution to your formula would seem to be just to extrapolate out multiple if statements:
=IF(H6="Vaga", QUERY(A2:D60, "SELECT * WHERE A "&H3&" '"&H9&"'"),
if(H6="Empresa", QUERY(A2:D60, "SELECT * WHERE C "&H3&" '"&H9&"'"),
If(H6="Postada", QUERY(A2:D60, "SELECT * WHERE E "&H3&" '"&H9&"'"),"nothing")))
try:
=QUERY(A2:D60, "where "&
CHOOSE(MATCH(H6, {"Vaga","Empresa","Postada"}, ), "A","C","E")&H3&" '"&H9&"'")
see: https://webapps.stackexchange.com/a/124685/186471
Related
I have the following data and the work-in-progress formula
=ARRAYFORMULA({unique(A2:A);flatten(UNIQUE(filter(C2:C, A2:A=A2))&": "&countif(filter(C2:C, A2:A=A2),UNIQUE(filter(C2:C, A2:A=A2))))})
How can I go about creating the DESIRED OUTPUT from the dataset?
Google Sheet link: https://docs.google.com/spreadsheets/d/1F-ZRe0hgFWdb318xHtiIGmR-RvxSgv518k9wCUBfCm0/edit?usp=sharing
The query() function lets you get those results, although they will be tabulated in a format that is different from what you requested:
=query(A1:C, "select A, count(A) where C is not null group by A pivot C", 1)
use:
=INDEX(LAMBDA(x, y,
QUERY(FLATTEN({SORT(UNIQUE(FILTER({IFERROR(x/0, ""), x}, x<>""))),
IF(QUERY(y, "offset 1", )="",,INDEX(y, 1)&": "&QUERY(y, "offset 1", ))}),
"where Col1 is not null offset 1", ))
(A2:A, QUERY(A2:C, "select count(A) where C is not null group by A pivot C")))
I got this one working fine, but it'd have to be an arrayformula:
=if(A3="","", COUNTA(filter(D:D,regexmatch(LOWER(D:D), LOWER(A3)))))
I have tried it like this, but it gives a total only in the cell the formula sits:
=ARRAYFORMULA(if(A3:A="","", COUNTA(filter(D:D,regexmatch(LOWER(D:D), LOWER(A3:A))))))
Here's the demo file:
Thanks in advance!
try:
=QUERY(D3:D,
"select D,count(D)
where D is not null
group by D
label count(D)''")
update 1:
=ARRAYFORMULA(QUERY({FILTER(D3:D, D3:D<>""),
FLATTEN(INDEX(QUERY(TRANSPOSE(REGEXMATCH(FILTER(D3:D, D3:D<>"")&"", ""&
TRANSPOSE(FILTER(A3:A, A3:A<>"")))*1),
"select "&TEXTJOIN(",", 1, "sum(Col"&SEQUENCE(COUNTA(D3:D))&")")),2))},
"select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col2)''"))
update 2:
=ARRAYFORMULA(FLATTEN(INDEX(QUERY(TRANSPOSE(IF(A3:A="",,
REGEXMATCH(IF(A3:A="",,TRANSPOSE(FILTER(D3:D, D3:D<>""))), A3:A)+0)),
"select "&TEXTJOIN(",", 1, "sum(Col"&SEQUENCE(COUNTA(A3:A))&")")), 2)))
update 3:
if column A contains empty cells in between
=ARRAYFORMULA(IFERROR(1/(1/FLATTEN(INDEX(QUERY(TRANSPOSE(IF(A3:A="",,
REGEXMATCH(IF(A3:A="",,TRANSPOSE(FILTER(D3:D, D3:D<>""))), A3:A)+0)+0),
"select "&TEXTJOIN(",", 1, "sum(Col"&SEQUENCE(MAX((A3:A<>"")*ROW(A3:A))-ROW(A3)+1)&")")), 2)))))
update 4:
one more alternative
=INDEX(IFERROR(1/(1/LEN(SUBSTITUTE(TRIM(FLATTEN(QUERY(TRANSPOSE(IFERROR(1/(1/IF(A3:A="",,
REGEXMATCH(IF(A3:A="",,TRANSPOSE(FILTER(D3:D, D3:D<>""))), A3:A)+0)))),,9^9))), " ", )))))
I am so frustrated. I don't know what happened but it was working before. This is my formula:
=QUERY(C3:M102,
"Select sum(C),sum(D),E,sum(F),sum(G),sum(H),sum(I),sum(J),sum(K),sum(L),sum(M)
where D>0
group by E
label sum(C)'',sum(D)'',sum(F)'',sum(G)'',sum(H)'',sum(I)'',sum(J)'',sum(K)'',sum(L)'',sum(M)''")
The info I am grabbing: https://imgur.com/a/8TkpbIf
try:
=QUERY(C3:M102,
"select sum(C),sum(D),E,sum(F),sum(G),sum(H),sum(I),sum(J),sum(K),sum(L),sum(M)
where D>0
group by E
label sum(C)'',sum(D)'',sum(F)'',sum(G)'',sum(H)'',sum(I)'',sum(J)'',sum(K)'',sum(L)'',sum(M)''", )
but this is better:
=QUERY(QUERY(C3:M102,
"select sum(C),sum(D),E,sum(F),sum(G),sum(H),sum(I),sum(J),sum(K),sum(L),sum(M)
where D>0
group by E"), "offset 1", )
I have a range of data on column A and B. In Column D , i have a reference for the shotID. I want to make a list for the artist involved for specific shotID.
In E2 i use this :
=JOIN( "," , FILTER($B$2:$B, $A$2:$A= D2))
then copy down to E3,E4. It works as i expected, but i want to do it using array formula. So only use single formula in E2 and that doesn't work that simple :
=arrayformula( JOIN( "," , FILTER($B$2:$B, $A$2:$A= D2:D4)) )
How can i do this ?
One more possibility that I learned from player0 and surprised he didn't suggest...
=ARRAYFORMULA(SPLIT(TRANSPOSE(SUBSTITUTE(TRIM(QUERY(QUERY(A2:B&{"|",CHAR(10)},"select MAX(Col2) where Col1<>'|' group by Col2 pivot Col1"),,100)),CHAR(10),",")),"| ",0))
take:
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(SUBSTITUTE(
FLATTEN(QUERY(TRANSPOSE(QUERY(QUERY(SPLIT(
FLATTEN(A2:A&"×"&B2:B&","&"×"&B2:B), "×"),
"select Col1,max(Col2) where Col2 is not null group by Col1 pivot Col3"),
"offset 1", 0)),,9^9)), " ", "×", 1), "×")), ",$", ))
You could also try:
={unique(A2:A),arrayformula(transpose(substitute(trim(query(if(A2:A<>transpose(unique(A2:A)),,B2:B),,9^9))," ",", ")))}
Currently, I have this
=QUERY(
QUERY(
'Raw Paste'!C2:E, "select C, count(C) where C is not null group by C order by C label count(C) ''"
), "WHERE Col2 >= 2")
The second QUERY() is so I can filter the aggregate function like an SQL HAVING function...
That will do this:
What I want to do though is next to the count, I want a 3rd column that joins the invoice numbers that are included in the aggregate.
This would be trivial with ARRAY_AGG(C) but google sheets ain't that fancy.
I've considered maybe using INDEX/MATCH somehow but I dunno.. I need to join the strings together where an item appears more than once.
C D
111 PPP
222 OOO
222 QQQ
The output I want:
C D
222 OOO, QQQ
It can be done by using FILTER and JOIN
=IFERROR(JOIN(", ", FILTER(D2:D, C2:C = A3)))
FILTER will look in C2:C for A2 and return the values from D2:D, which get passed to JOIN
=ARRAYFORMULA(REGEXREPLACE(TRIM({QUERY(QUERY(C:D,
"select C,count(C) where C is not null group by C pivot D", 0), "select Col1 offset 1", 0),
TRANSPOSE(QUERY(TRANSPOSE(IF(ISNUMBER(QUERY(QUERY(C:D,
"select count(C) where C is not null group by C pivot D", 0), "offset 1", 0)),
QUERY(QUERY(C:D,
"select count(C) where C is not null group by C pivot D", 0), "limit 0", 1)&",", ))
,,999^99))}), ",$", ))