Google Sheets - Using INDIRECT (or alternative) within a query - google-sheets

I am currently using this formula:
=SORT(QUERY(G:Z, "select K,count(K) where K is not null group by K label count(K)''"),2,TRUE)
I have to replace all instances of "K" with a column letter that is written in cell B2, so I can quickly change the entire formula by simply entering the letter in the cell.
Any advice?
Thanks

Use string concatenation:
=SORT(QUERY(E:K, "select " & D1 &" ,count(" & D1 &") where " & D1 &" is not null group by " & D1 &" label count(" & D1 &")''"),2,TRUE)

as already suggested here use:
=INDEX(QUERY({INDIRECT(
ADDRESS(1, MATCH(B1, CHAR(ROW(A65:A99)), 0), 4)&":"&
ADDRESS(100000, MATCH(B1, CHAR(ROW(A65:A99)), 0), 4))},
"select Col1,count(Col1) where Col1 is not null
group by Col1 label count(Col1)''"))
demo sheet

Related

How to join data from different sheets using Query in Google Sheets

I am trying to make a simple cash book.
As shown in the picture, from the cash-In and Cash-Out sheets i need to consolidate and display in the monitor sheet according to the selected party.
It should be sorted by date.
sheet link: https://docs.google.com/spreadsheets/d/1BwtcDIJv_CiZ-7Ae8qgLr4Azttnn7pBIOoxxMxdi2fk/edit?usp=sharing
Try this query-
=QUERY({QUERY('Cash In'!A2:C,"select A, C,0 where B='" & B1 & "'");
QUERY('Cash Out'!A2:C,"select A, 0, C where B='" & B1 & "'")},
"where Col1 is not null order by Col1 label Col1 'Date', Col2 'Cash In', Col3 'Cash Out'")
See sheet harun24hr.
This formula will solve your problem. First goto Monitor sheet then delete A3,B3 and C3 cells. Then put this formula on A3 cell.
=QUERY(UNIQUE({query('Cash In'!A1:C, "select A, C, 'Cash In' WHERE A is not null AND B ='"&$B$1&"'", 0);query('Cash Out'!A1:C, "select A, C, 'Cash Out' WHERE A is not null AND B ='"&$B$1&"'",0)}), "SELECT Col1, SUM(Col2) WHERE Col1 is not null group by Col1 PIVOT Col3 order by Col1 Label Col1 'Date'")
Get Cash In values query('Cash In'!A1:C, "select A, C, 'Cash In' WHERE A is not null AND B ='"&$B$1&"'", 0) and add a virtual column with Cash In with selected filter on B1 cell at Monitor sheet
Get Cash Out values query('Cash Out'!A1:C, "select A, C, 'Cash Out' WHERE A is not null AND B ='"&$B$1&"'",0)} and add a virtual column with Cash Out with selected filter on B1 cell at Monitor sheet
Then merge two data in a single result. (Vertically merge) UNIQUE({data_frame1, data_frame2})
In last step transpose PIVOT and sort by date column
Result:

Excel Formula for counting words with same starting letters

Suppose I have a column of words, in some cases more than 1 word in each cell, separated by a comma or space. I want to calculate the number of words starting with A, B, C...,Z separately.
try:
=ARRAYFORMULA(QUERY(IFERROR(FLATTEN(REGEXEXTRACT(SPLIT(A1:A10; ", "); "^.")));
"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1)''"))
or:
=ARRAYFORMULA(QUERY(IFERROR(UPPER(FLATTEN(REGEXEXTRACT(SPLIT(A1:A10, ", "), "^.")))),
"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1)''"))

Join range of row using arrayformula

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))," ",", ")))}

Display percentage symbol in column A using Arrayformula

I have a sheet query result which I need to display with the % for A column
The expected result is
I have the query result formula as
=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 ''"))
I cannot use custom number format menu since this ranges is to be combined with other ranges in above cells using {;}
Add &{"%",""} before the closing arrayformula bracket.
=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 ''")&{"%",""})

Making an ArrayFormula from QUERY

How do I convert this:
=if(ISNA(sum(QUERY(importrange("1QNYU1Kb1rtx-n4tMRamHJuvYt_9kGMfhGZZs_opuJr0","Transfer!C$2:E"),"SELECT Col3 WHERE Col1 = '" & Sheet1!B$2:B & "' ",0))),"0",sum(QUERY(importrange("1QNYU1Kb1rtx-n4tMRamHJuvYt_9kGMfhGZZs_opuJr0","Transfer!C$2:E"),"SELECT Col3 WHERE Col1 = '" & Sheet1!B$2:B & "' ",0)))
into the array formula in Google Sheets?
in my opinion, it would be pretty much an overkill if it would be possible. instead I recon to do this:
use side columns (or create a new sheet in PRC Records spreadsheet) and paste this formula there:
=QUERY({Transfer!A1:H}, "select Col3, sum(Col5)
where Col3 is not null
group by Col3
label sum(Col5)'FG Qty'", 1)
and then use this formula in J2 cell over on the MO Listing spreadsheet:
=ARRAYFORMULA(IF(LEN(B2:B), IFERROR(VLOOKUP(B2:B,
IMPORTRANGE("1QNYU1Kb1rtx-n4tMRamHJuvYt_9kGMfhGZZs_opuJr0",
"Transfer!L2:M"), 2, 0), 0), ))

Resources