Formatting 3 column array in Google Sheets with unique counts - google-sheets

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

Related

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

Returning top value of column from range in google sheets

Say I had a list like this.
Group 1 Group 2
Edward, C Kate, A
Mark, F Ava, Z
Now, in a different column =IF(COUNTIF('Gender'!$A$2:$B$3, "Kate, A"), "", "") is my current formula. I would like to make the first set of empty speech marks return Group 1 or Group 2 depending what column it is. I still require the COUNTIF because my actual sheet has values which will not be contained in either column.
Thanks.
try:
=INDEX(IFNA(VLOOKUP("Kate, A", SPLIT(FLATTEN(
IF(Gender!A2:B="",,Gender!A2:B&"×"&Gender!A1:B1)), "×"), 2, 0)))
update:
=INDEX(IFNA(VLOOKUP(A1:A, QUERY(SPLIT(FLATTEN(
IF(Groups!B2:C="",,Groups!B2:C&"×"&Groups!A1&"×"&Groups!B1:C1),
IF(Groups!F2:G="",,Groups!F2:G&"×"&Groups!E1&"×"&Groups!F1:G1)), "×"),
"select Col1,max(Col3) where Col2 is not null
group by Col1 pivot Col2 label Col1'"&A1&"'"), {2, 3}, 0)))
demo sheet

How can I get a QUERY to CONCATENATE text after it combines data?

On this sheet, I've been working on I have the info I need adjusting down into the Query Results
=QUERY(Investors!A4:D,
"select B,C,sum(D)
where B is not null
group by B,C
label sum(D)''")
How do I get the Stock Numbers Due that day to be listed out in column D? Like this:
1. 10/7/2019 Grady Johnson $100.12 PT-1013
2. 11/15/2020 Bill Jones $553.80 PT-1020, PT-1019
3. 11/15/2020 Grady Johnson $45.00 PT-1011
4. 11/15/2020 Steve Robinson $320.00 PT-1018, PT-1016
5. 11/17/2020 Jim Luke $1,057.20 PT-1009, PT-1008, PT-1007, PT-1006
6. 11/22/2020 Jim Luke $300.43 PT-1010
Here's the link: Google Sheet
Any help is appreciated!
or paste this in row 3 and drag down:
=JOIN(", ", IFNA(FILTER(Investors!A$4:A, Investors!B$4:B&" "&Investors!C$4:C=A3&" "&B3)))
try:
=ARRAYFORMULA(REGEXREPLACE(IFNA(VLOOKUP(TO_TEXT(A3:A)&" "&B3:B,
TRIM({TRANSPOSE(QUERY(TRANSPOSE(QUERY(QUERY({Investors!A4:C},
"select Col2,Col3,count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"select Col1,Col2 offset 1", 0)),,9^9)),
TRANSPOSE(QUERY(TRANSPOSE(IF(QUERY(QUERY({Investors!A4:C},
"select count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"offset 1", 0)="",,
QUERY(QUERY({Investors!A4:A&",", Investors!B4:C},
"select count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"limit 0", 1))),,9^9))}), 2, 0)), ",$", ))
Here is my suggested formula to be placed in Combined!D3 of your sample spreadsheet:
=ArrayFormula(IF(A3:A="",,SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(VLOOKUP(TRANSPOSE(FILTER(Investors!A4:A,Investors!A4:A<>"")),{Investors!A:A,Investors!C:C&Investors!B:B},2,FALSE)=B3:B&A3:A,TRANSPOSE(FILTER(Investors!A4:A,Investors!A4:A<>"")),))," ",COUNTA(Investors!A4:A))))," ",", ")))
As for how it works, that would be time-consuming to explain. (More time than is reasonable for a free site such as this.) I will suggest that, if this is important to you, take the time to study it. Take it apart and see what each piece does — separately and then in combination with other parts — until you've gotten it all back together.

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

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