Google Sheets outer join on 2 tables that get summarised - google-sheets

I have a report I am developing that needs to be in google sheets
Sheet 1 contains all the current cases that are opened and owned by a case owner, 1 row per case, multiple cases per case owner per month (sample sheet has 4 months of data)
Sheet 2 contains all the cases that were closed and who closed them, 1 row per case, multiple cases per case owner per month (sample sheet has 4 months of data)
There could be case owners in the open sheet that don't exist in the closed sheet
There could be case owners in the closed sheet that don't exist in the open sheet
I know how create a query() function that summarises both raw data separately - what I want to be able to do is query a joined table to get open and closed cases in 1 table.
In the sample file there are 2 tables in A5 and F5. These were me looking at how the query() function worked - the actual report I want is in K5
Where I am struggling is bringing this together into one summary report which shows the last 3 months of data
To clarify - what I want to do is have one function that queries from the 2 RAW sheets and creates the summary report
The sample sheet should more clearly explain what I need to do
https://docs.google.com/spreadsheets/d/1QEd9ZauY0YrbRWNu35tDTk6SkL1PaIZLtSOCd1A2fDY/edit?usp=sharing
Output for the OPEN cases:
=query('Raw Data'!A:N,"Select B, count(A) where N >= date '2020-02-01' group by B pivot N")
Output for the CLOSED cases
=query('Raw Data - Closed'!A:N,"Select A, count(B) where H >= date '2020-02-01' AND H <= date '2020-04-01' group by A pivot H")
Any pointers?

try:
=ARRAYFORMULA(SUBSTITUTE(TRANSPOSE(QUERY(TRANSPOSE({{
IF(ISNUMBER(A5:D5*1), A5:D5&" A"&A3, A5:D5); A6:D},
IFNA(VLOOKUP(A5:A, {IF(ISNUMBER(F5:I5*1), F5:I5&" "&F3, F5:I5); F6:I},
COLUMN(G5:I5)-(COLUMN(F5)-1), 0))}), "order by Col1", 1)), " AOpen", " Open"))
=ARRAYFORMULA(SUBSTITUTE(TRANSPOSE(QUERY(TRANSPOSE({{
IF(ISNUMBER(
QUERY('Raw Data'!A:N, "select B,count(A) where N >= date '2020-02-01' group by B pivot N limit 0")*1),
QUERY('Raw Data'!A:N, "select B,count(A) where N >= date '2020-02-01' group by B pivot N limit 0")&" AOpen",
QUERY('Raw Data'!A:N, "select B,count(A) where N >= date '2020-02-01' group by B pivot N limit 0")); QUERY(
QUERY('Raw Data'!A:N, "select B,count(A) where N >= date '2020-02-01' group by B pivot N"), "offset 1", 0)},
IFNA(VLOOKUP(INDEX(
QUERY('Raw Data'!A:N, "select B,count(A) where N >= date '2020-02-01' group by B pivot N"),,1), {IF(ISNUMBER(
QUERY('Raw Data - Closed'!A:N, "select A,count(B) where H >= date '2020-02-01' and H <= date '2020-04-01' group by A pivot H limit 0")*1),
QUERY('Raw Data - Closed'!A:N, "select A,count(B) where H >= date '2020-02-01' and H <= date '2020-04-01' group by A pivot H limit 0")&" Closed",
QUERY('Raw Data - Closed'!A:N, "select A,count(B) where H >= date '2020-02-01' and H <= date '2020-04-01' group by A pivot H limit 0")); QUERY(
QUERY('Raw Data - Closed'!A:N, "select A,count(B) where H >= date '2020-02-01' and H <= date '2020-04-01' group by A pivot H"), "offset 1", 0)},
SEQUENCE(1, COLUMNS(
QUERY('Raw Data - Closed'!A:N, "select A,count(B) where H >= date '2020-02-01' and H <= date '2020-04-01' group by A pivot H"))-1, 2, 1), 0))}), "order by Col1", 1)), " AOpen", " Open"))

Related

How to use Query Function to list all Salesman according to the Date Range and Total Sales Range?

For example:
From 4/14 to 5/1, List the saleman whose total sales range is within $30 ~ $50
The Result should be:
Salesman 0196
(Because his total sales is $47.95 from From 4/14 to 5/1 )
I sincerely need your help to write a Query Function to list all Salesman according to the Date Range and Total Sales Range ? Thank you so much
https://docs.google.com/spreadsheets/d/13pIdJOtshK2mv4B2II8gAjKvL9uIjg87LHzREZNEtbE/edit?usp=sharing
In the spreadsheet you shared I entered this formula
=query(query(A:E, "Select B, sum(E) where A >= date '"&text(I1, "yyyy-mm-dd")&"' and A <= date '"&text(K1, "yyyy-mm-dd")&"' group by B", 0), "where Col2 > "&I2&" and Col2 < "&K2&" order by Col2 desc label Col1 'Salesman', Col2 'Total Sales'", 0)
See if that works for you?

Google Sheet Query with Importrange and Date today

=QUERY(IMPORTRANGE("xxxxxxx-Sheet-ID"; "Tabelle1!A:D"),
"where C > date'" & text(today(), "yyyy-mm-dd") & "'
and D < date'" & text(today(), "yyyy-mm-dd") & "'", 0)
Can someone told me, why this is not working?
I will get the row informations where the C date is smaller and the D date is bigger than today date.
I the table where i look is this formation 2021-03-29of date
I tried this code above but this is not working... It says ERROR! but i dont see any logs
Assuming you granted permission to pull data from other spreadsheets, try:
=QUERY(IMPORTRANGE("xxxxxxx-Sheet-ID"; "Tabelle1!A:D"); "where C > date '"& text(today(); "yyyy-mm-dd")&"' and D < date '"& text(today(); "yyyy-mm-dd") &"'"; 0)
and see if that works? If not, please share a copy of your spreadsheet (sensitive data erased) so we see how your data is structured.
Note that importrange is only needed if you import data from another spreadsheet. Data imports from within the same spreadsheet can be done without it.
You have to replace C by Col3 and D by Col4 (you can't use A, B, C and D in that case)
=query(IMPORTRANGE("___________","Tabelle1!A:D"), "where Col4 > date '"& text(today(), "yyyy-mm-dd")&"' and Col3 < date '"& text(today(), "yyyy-mm-dd") &"'", 0)
switch Col3 and Col4 as necessary

Google sheets "array_agg"... or equivalent? (join aggregation)

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

Matching a dynamic array of rows to a dataset

So I have a large data set of products, (in my case, boxes of floor tiles).
each product has five related columns:
The product name ("Stone-Grey", "Cubic-Dark", etc)
The product series ("P-26", "D-25-A", "26-A-C", etc)
The warehouse where the product is stored ("P1", "D4", "A3", etc)
The shelf number where the product is stored ("1", "17", "25", etc)
The number of units within each box
There is quite a mess with the stock, and I need to rearrange some of it.
The problem is that the stock is dynamic, and I need my lists to be dynamic also.
My end goal is to list all the boxes with less than X items in the box and match all similar products (similar product = has the same name and series), and where exactly it's located (warehouse and shelf).
I've succeeded in creating the dynamic list of lacking boxes using The QUERY function, and also in creating a formula for the second part (matching all similar products, and their location).
The problem is it's a drag-down formula, and I need a dynamic formula, based on the size of the former list.
The first list is pretty much straight forward:
=Arrayformula(Concat(QUERY('Tiles_stock'!$A$4:AC$216,"Select A Where R < 0.13"),(Concat("_",QUERY('Tiles_stock'!$A$4:AC$216,"Select C Where R < 0.13")))))
The formula returns the warehouse and the shelf, matched together.
Now the tricky part, the second formula is:
=Textjoin(" , ",True, Arrayformula(Concat(QUERY('Tiles_stock'!$A$4:X$216,"Select A where N contains '"& O4 &"' AND O contains '"& P4 &"' AND R > 0.13 "),(Concat("_",QUERY('Tiles_stock'!$A$4:X$216,"Select C where N contains '"& O4 &"' AND O contains '"& P4 &"' AND R > 0.13 "))))))
Which works fine, but forces me to drag it down or up each time the first list has changed (as I said, it's a stock, and it's dynamic).
Here's an image of what I'm basically trying to achieve:
https://drive.google.com/file/d/1UIim9oFRyOqYZpzcg9VsYvzuffP6sQ7F/view?usp=sharing
Here's a link to the spreadsheet:
https://docs.google.com/spreadsheets/d/13q7EBz18z6t_iMVTT-M7fzcPjtdYligYjz_m90h_z3A/edit?usp=sharing
list all the boxes with less than X items in the box and match all similar products (similar product = has the same name and series)...
=ARRAYFORMULA(QUERY({QUERY(
QUERY(QUERY({A2:A&" "&B2:B, C2:C&"_"&D2:D, E2:E},
"select Col1,Col2 where Col3 >= 10", 0),
"select Col1, count(Col1) group by Col1 pivot Col2", 0),
"select Col1", 0),
REGEXREPLACE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(ISNUMBER(
QUERY(QUERY({A2:A&" "&B2:B, C2:C&"_"&D2:D, E2:E},
"select Col1,Col2 where Col3 >= 10", 0),
"select count(Col1) group by Col1 pivot Col2", 0)),
QUERY(QUERY({A2:A&" "&B2:B, C2:C&"_"&D2:D, E2:E},
"select Col1,Col2 where Col3 >= 10", 0),
"select count(Col1) group by Col1 pivot Col2 limit 0", 0)&",", )),,999^99))), ",$", )},
"offset 1", 0))

Google Sheets formula to calculate sum of values in one column which match multiple columns in another sheet

I need a formula in Sheet 2 column D which will look up the values of columns B and C in Sheet 1 column A and calculate the sum of the values in column C. So for example, D2 will return 36.
Sheet 1:
Sheet 2
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, QUERY({Sheet1!B:C},
"select Col1, sum(Col2) where Col1 != '' group by Col1", 0), 2, 0)))

Resources