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

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

Related

Formatting 3 column array in Google Sheets with unique counts

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

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

Transpose multiple rows into column in Google sheet

I want to use transpose formulae in this data
and I want desire output will look like this
try:
=QUERY(A2:B, "select max(B) where A is not null group by B pivot A")
or:
=ARRAYFORMULA(SUBSTITUTE(TRANSPOSE(SPLIT(TRANSPOSE(QUERY(QUERY(
{SUBSTITUTE(A2:A, " ", "♥"), B2:B},
"select max(Col2)
where Col1 is not null
group by Col2
pivot Col1"),,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))

Search column of one sheet and return multiple matches from a separate sheet in CSV

I am trying to search Data!A2:A for multiple matches to Search!A2:A. When a match is found, get the value(s) from Data!B2:B and place them in CSV format in Search!B2:B.
This QUERY works, but I would like to somehow only enter it one time at the top of the column rather than fill it down manually. When I attempted to wrap it in ARRAYFORMULA, I simply replicated the first result down the column.
=JOIN(", ",QUERY(Data!$A$2:$B,"SELECT B WHERE A = '"&A2&"'",0))
Here is my sample spreadsheet
=ARRAYFORMULA(REGEXREPLACE(TRIM(IFERROR(VLOOKUP(A2:A, {QUERY(QUERY(Data!A2:B,
"select A,count(A) where A is not null group by A pivot B", 0), "select Col1 offset 1", 0),
TRANSPOSE(QUERY(TRANSPOSE(IF(ISNUMBER(QUERY(QUERY(Data!A2:B,
"select count(A) where A is not null group by A pivot B", 0), "offset 1", 0)),
QUERY(QUERY(Data!A2:B,
"select count(A) where A is not null group by A pivot B", 0), "limit 0", -1)&",", ))
,,999^99))}, 2, 0))), ",$", ))

Resources