I have the yellow table shown below, and I'm trying to get the blue table, which aggregates columns B:F by value, and then counts the number of 'x' symbols for each row value of column A.
Is there some basic SQL/array magic formula to get this, please? There must be.
Use this new functions formula
=BYROW(B2:4, LAMBDA(v, COUNTIF(v, "=x")))
Used:
BYROW, LAMBDA, COUNTIF
v is the array_or_range
Update
={ A2:A4, BYROW(B2:4, LAMBDA(vv, COUNTIF(vv, "=x")))}
For fun
Update 02
=ArrayFormula(TRANSPOSE(QUERY({
QUERY(TRANSPOSE(IF(A1:4<>"x",A1:4,1)),
" Select * Where Col1 is not null ", 1)},
" Select (Col1),sum(Col2),sum(Col3),sum(Col4) Group by Col1 ", 1)))
I have a Search sheet searching for transactions through a Ledger sheet. The date is mandatory but all other parameters are optional. Problem being how to reference the optional parameter which is on the Search sheet and not in the Ledger sheet, i.e.
WHERE J not empty cell AND (J=A3) AND (C=C3 OR C3="") AND (F=F3 OR F3="")
(J, C, F is on Ledger sheet, A3, C3, F3 is on Search sheet)
QUERY(Ledger!A6:J, "Select J,B,C,D,E,F,G WHERE J is not null AND (J= '" & text(A3,"yyyy-MM-dd") & "' ) AND (...) AND (...) ")
Here is my example, the date part is working:
https://docs.google.com/spreadsheets/d/1vD-9IVc0bpPnNi3Bo85igYTtCbV9eP_3BjY3It2lPf0/edit#gid=1964422536
SupplierLedgerSearch
Because QUERY() treating first of of range Ledger!A6:J as header. So, use header parameter 0 to tell query function not to return header row. Try-
=QUERY(Ledger!A6:J, "Select J,B,C,D,E,F,G WHERE J is not null AND (J= '" & text(A3,"yyyy-MM-dd") & "' ) ",0)
Reference:
QUERY Google Sheet function.
I want to write a query to combine data from two sheets with same heading where data in first column is either a date or a specific string.
Example
=query({Sheet1!A:B;, Sheet2!A2:B}, "select * where Col1 > date 'YYYY-MM-DD' OR Col1 = 'example string' ")
The values are reflecting for date but not for the example string.
The example string entered for Col1 in the formula, is selected from a pulldown list in sheet2.
better try:
=FILTER({Sheet1!A:B; Sheet2!A2:B},
({Sheet1!A:A; Sheet2!A2:A}>"01/01/2000")+({Sheet1!A:A; Sheet2!A2:A}="example text"))
I am trying to combine two tabs of data to plan a daily routine. One tab is for recurring tasks and one for adhoc tasks.
The data on the tabs are mostly similar except on Sheet1 Col4 is a day of the week, whereas on Sheet2 Col4 is a date
What I would like is to choose the current day of the week and have the query return all recurring tasks for that day, as well as any adhoc tasks for that specific date
I can return both sets of data individually however I can't get the query to return both subsets together
Sheet1 Data
ID,TASK NAME,LOCATION,TASK DAY
REC1,Task 1,Office,Monday
REC2,Task 2,Office,Tuesday
REC3,Task 3,Field,Wednesday
REC4,Task 4,Office,Thursday
REC5,Task 5,Field,Friday
REC6,Task 6,Field,Monday
REC7,Task 7,Field,Tuesday
Sheet2 Data
ID,TASK NAME,LOCATION,TASK DATE
ADH1,AdHoc 1,Office,25/Jun/2019
ADH2,AdHoc 2,Office,26/Jun/2019
ADH3,AdHoc 3,Field,27/Jun/2019
ADH4,AdHoc 4,Office,28/Jun/2019
ADH5,AdHoc 5,Field,29/Jun/2019
ADH6,AdHoc 6,Field,30/Jun/2019
ADH7,AdHoc 7,Field,1/Jul/2019
This pulls the data from sheet 1 based on the day of the week in cell J1
=query({Sheet1!A:D}, "select Col1,Col2,Col3,Col4 where Col4 = """&J1&""" ",0)
This pulls the data from sheet 2 based on today()
=query({Sheet2!A:D}, "select Col1,Col2,Col3,Col4 where Col4 = date '" & text(today(),"yyyy-mm-dd") & "' ",0)
Thought this would work but merely returns an empty set
=query({Sheet2!A:D;Sheet1!A:D}, "select Col1,Col2,Col3,Col4 where Col4 = date '" & text(today(),"yyyy-mm-dd") & "' OR Col4="""&J1&""" and Col1<>'' ",0)
When J1 = Tuesday and date = 25/Jun/2019 I should get
ID,TASK NAME,LOCATION,TASK DAY
ADH1,AdHoc 1,Office,25/Jun/2019
REC2,Task 2,Office,Tuesday
REC7,Task 7,Field,Tuesday
but instead, merely get #N/A
You almost had it.
Rather than put the array inside the queries; put the queries inside the array.
={QUERY(Sheet1!A:D, "SELECT A, B, C, D WHERE D = """&J1&""" ");
QUERY(Sheet2!A2:D, "SELECT A, B, C, D WHERE D = date '" & text(today(),"yyyy-mm-dd") & "'")}
Credit - Stacking multiple query output in one sheet:
Might be too late but issue was in date column after converting it to text query works as well :
=query({Sheet2!A:D; Sheet1!A:D}, "select Col2,Col1,Col3,Col4 where (Col4='"&Sheet1!J1&"' OR Col4 = '" & to_text(today()) & "')",0)
I am trying to use QUERY() to call a column of data from one sheet to another based on the contents of other columns. The code below works just fine.
=query(Data!$A1:$Y15), "select Col7 where Col1 starts with """&E$2&""" ")
However, I want to copy this data and have Col7 change to match the row of the cell that the formula is in + 1. It should be something like this (the formula is in cell F6):
=query(Data!$A1:$Y15), "select Col"""Row(F6) + 1""" where Col1 starts with """&E$2&""" ")
How can I concatenate or insert a number into a query string? I do need to use query due to some other constraints I simplified out of this example.
Just use & for concatenation, the way you did around E$2.
"select Col" & Row(F6) + 1 & " where Col1 starts with """ & E$2 & """ "
I would also use single quotes around the string from E$2, because they don't need to be escaped by doubling:
"select Col" & Row(F6) + 1 & " where Col1 starts with '" & E$2 & "'"
Also, Row(F6) could be simply Row() which returns the row of the current cell.