Google Sheets: Query With Dynamic Dates - google-sheets

I have a table in Google Sheets and I would like to create a query with dynamics dates. The structure of the table is as follows:
Col A as client_name
Col B as product
Col C as purchase_date
I tried to do this but it didn't work:
Query(A:B;"Select A,B Where C > '&D1&' AND C < '&E1&'")
D1 as initial_dynamic_date, E1 as final_dynamic_date
I would like to be able to filter by dynamic cells D1 and E1
Thanks.

there are 2 options:
=QUERY(A:B;
"select A,B
where C > &D1*1&
and C < &E1*1)
or:
=QUERY(A:B;
"select A,B
where C > date '&TEXT(D1; "e-m-d")&'
and C < date '&TEXT(E1; "e-m-d")&'")

Related

Google Sheets: Creating a formatted list based off Form Results

I am working on a voting form to rank some things (A, B, C, D, F) using Google Forms. I have it set up to import the results into Google Sheets. What I am trying to do is to then take the results and sort them in another sheet by their rankings.
So the result of the form looks something like this:
Item A
Item B
Item C
Item D
Item E
Item F
Item G
A
B
F
C
F
A
F
B
C
F
C
D
A
F
B
A
D
C
F
A
F
B
B
D
C
D
B
F
I then have a formula that finds the majority ranking for each item and places them into another sheet, which looks like this:
Item A
Item B
Item C
Item D
Item E
Item F
Item G
B
B
D
C
D
A
F
My goal is to have the final sheet transpose that table and sort them alphabetically by their voted upon ranking. So using the dataset above, it would look like this:
Rank A
Rank B
Rank C
Rank D
Rank F
Item F
Item A
Item D
Item C
Item G
Item B
Item E
Is this something that is possible to automate in Google Sheets? Currently I am doing the last part manually, but I would love to have it auto-add each ranked item to the correct column and if possible, sort them alphabetically in their respective ranks.
try:
=ARRAYFORMULA(SUBSTITUTE(TRANSPOSE(SPLIT(FLATTEN(QUERY(
QUERY(TEXT(TRANSPOSE(SUBSTITUTE(A1:G2, " ", "×")), {"#", "Rank×#"}),
"select max(Col1) group by Col1 pivot Col2"),,9^9)), " ")), "×", " "))
I have created this example, you will need to change the ranges in the formula to match with your data.
=TRANSPOSE(INDEX(FILTER(A1:G1, A2:G2 = "A")))
Add the above formula below each “Rank” column and change the letter “A” to the respective ranking.

How to sum by category in Google Sheets and manipulate the result?

I have this format:
A B C D
invoice date product amount
D1 P1 10
D1 P2 100
D1 P1 10
I1 D1 P1 10
I want to calculate the sum of non-invoiced products by product. I'm almost there with this:
=query($A$2:$D;"select C, sum(D) where A is null group by C")
sum
P1 20
P2 100
But I actually want to split this result (ignoring the "sum" header) and put it into two non-adjacent columns E and G:
E F G
row1 P1 20
ro22 P2 100
I guess I could write two separate array queries, one for E1 and another for G1, but I'm still not sure how to extract pieces of the QUERY result (and there might be a simpler approach than using QUERY).
Live example
Unfortunately, ignoring columns in a formula is not possible. You need to create 2 QUERY functions.
Try these formulas:
For cell E8: =QUERY(QUERY(A2:D5, "SELECT C, SUM(D) where A is null group by C label SUM(D) ''"), "SELECT Col1")
For cell G8: =QUERY(QUERY(A2:D5, "SELECT C, SUM(D) where A is null group by C label SUM(D) ''"), "SELECT Col2")
Example:
Reference:
QUERY

google sheets query date only brings one row result

I have a tab call (Data Import) where I have the whole raw data imported in google sheets, in the next tab I have my query that looks as below;
This is the query -> =QUERY('Data Import'!$I1:$O, A1, 1)
A1 is equal to -> ="SELECT K, O, J WHERE J >= "&F1&""
F1 is equal to -> 44196
The result I get is only the first row, but I want all the rows that contains the same date which are a total 25 plus the header with the column names.
Does anyone figures what I am doing wrong?
try in A1:
=QUERY('Data Import'!I1:O,
"SELECT K,O,J WHERE J >= "&F1*1, 1)
you could also solve it like:
=QUERY('Data Import'!I1:O,
"SELECT K,O,J WHERE J >= date '"&TEXT(F1, "yyyy-mm-dd")&"'", 1)

How to reference two columns from two different sheets in one query

I'm trying to write a query that looks compares strings within a cell on two different pages. This is the query I have written but it says unable to parse query string because there is no column b4.
=QUERY(Teams!B:F, "select F where B = B4", 0)
Note column B is on a different page than B4.
if B4 is number do:
=QUERY(Teams!B:F, "select F where B = "&B4, 0)
if B4 is not number do:
=QUERY(Teams!B:F, "select F where B = '"&B4&"'", 0)

Improve Query Function in Google Sheets

I've been using the following function:
=query(Sheet1!A2:D," select A, B, C where A matches '"&JOIN("|", A2:A)&"' and D matches 'yes'")
Is there anyway that I can make is so that every row that starts with a match will be added a comma separated list in which each column occupies one cell with no duplicates as shown in sheet3.
https://docs.google.com/spreadsheets/d/1YDxIUnZzzYde9hcexPoDegv4HBuiUwk2wLKSXazu9hE/edit?usp=sharing
Sheet 2 has the function that I used and the result.
It is not entirely clear what you want to do, but try this. In Sheet1 in E2 put this combining Col A and D:
=arrayFormula(A2:A & if(isBlank(D2:D),""," ") & D2:D)
In F2 combine Col C and D with this:
=arrayFormula(B2:B & if(isBlank(C2:C),"",",") & C2:C)
In G2 find the unique values from Col F with this:
=UNIQUE(E2:E)
In H2 put this and drag the formula down:
=join(",",query(E2:F,"select F where E contains '"& G2 &"'"))
Hide Cols E & F

Resources