Troublesome syntax - ArrayFormula + CONC + Filter - google-sheets

Example
I have this line:
=ARRAYFORMULA(IFERROR(CONCATENATE(SORT(FILTER('Personale-vagter-AFKRYDS'!$B$3:$B$7 & " ",ARRAYFORMULA('Personale-vagter-AFKRYDS'!**G3**:**G7**=TRUE)),1,TRUE)),"error"))
...And it works, but when I try to expand from G3 + G7 to this (C3 + G37):
=ARRAYFORMULA(IFERROR(CONCATENATE(SORT(FILTER('Personale-vagter-AFKRYDS'!$B$3:$B$7 & " ",ARRAYFORMULA('Personale-vagter-AFKRYDS'!**C3**:**G37**=TRUE)),1,TRUE)),"fejl"))
... It doesn't work.
What am I doing wrong?

all ranges in FILTER needs to be the same size. try:
=ARRAYFORMULA(IFERROR(CONCATENATE(SORT(
FILTER('Personale-vagter-AFKRYDS'!B3:B37&" ",
'Personale-vagter-AFKRYDS'!G3:G37=TRUE), 1, 1)),"error"))
UPDATE:
=ARRAYFORMULA(IFNA({
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!C3:C=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0),
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!D3:D=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0),
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!E3:E=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0),
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!F3:F=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0),
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!G3:G=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0)}))

Please use this in B3 and drag in other cells
ARRAYFORMULA(IFERROR(CONCATENATE(SORT(FILTER(OFFSET('Personale-vagter-AFKRYDS'!$B$3:$B$37,0+(5*(row(A1)-1)),0,5,1) & " ",OFFSET('Personale-vagter-AFKRYDS'!C$3:C$37,0+(5*(row(A1)-1)),0,5,1)=TRUE),1,TRUE)),"fejl"))

Related

Google Sheet combining two/three sets of col and calculate unique values with each

I have the following
col1 col2 col3 col4
NY sys1 DB1 4
CA sys1 DB1 2
CA sys1 DB1 1
MI sys1 DB1 1
DC sys1 DB2 2
MI sys1 DB2 2
In google sheets I want the output to look like this. Note: records in DB1 need to be counted separately and DB2 separately, but unique within each DB, and output I don't want to repeat DB1 with each record, as all records in the next col are from DB1. Only display DB1 one and then when the DB changes, then display the new one once and display and count its own records
DB1 NY 4
CA 3
MI 1
DB2 DC 2
MI 2
I tried the formula suggested but it keeps giving me parsing error not sure what I am doing wrong
Here is what I a typing
My actual is as follows: Of course, col B is showing the same data in the snapshot, but since other values are way down so could not capture other different values. Please assume that Col B has different values.
My actual data
try:
=ARRAYFORMULA({IF(COUNTIFS(
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0),
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0), ROW(INDIRECT("F1:F"&COUNTA(
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0)))), "<="&ROW(INDIRECT("F1:F"&COUNTA(
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0)))))=1,
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0), ),
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col2,Col3", 0)})
EU syntax:
=ARRAYFORMULA({IF(COUNTIFS(
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0);
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0); ROW(INDIRECT("F1:F"&COUNTA(
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0)))); "<="&ROW(INDIRECT("F1:F"&COUNTA(
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0)))))=1;
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0); )\
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col2,Col3"; 0)})

How can I JOIN the ARRAY results of this formula with a ","?

I've tried to add JOIN to this formula in every place I can think of, but none seem to be correct.
=ARRAYFORMULA(IFERROR(VLOOKUP(D2:D&E2:E,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦♥"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)))
The results are multiple columns/rows. I want to keep the rows, but JOIN the column values with a ",".
my sheet
like this perhaps:
=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(SUBSTITUTE(IFERROR(VLOOKUP(D2:D&E2:E,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦♥"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)), " ", "♫")),,999^99))), " ", ", "), "♫", " "))

Search 2 columns and return all matches in a transposed row

I'm trying to take this QUERY:
=IFERROR(TRANSPOSE(QUERY(Items!$A$2:$D,"SELECT D WHERE A = '"&A2&"' and B = '"&B2&"' and C = '"&C2&"' and C is not NULL and D is not NULL", 0)),)
And turn it into a formula that I can enter one time at the top of a sheet and have it apply to all cells in the column below.
I've tried manipulating various other formulas and answers I've found/received here on SO, but getting nothing but errors.
My sheet
=ARRAYFORMULA(IFERROR(VLOOKUP(Estimate!A2:A&Estimate!B2:B,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(Items!A2:A&Items!B2:B))*(LEN(Items!C2:C)),
Items!A2:A&Items!B2:B&"♦"&Items!C2:C, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(Items!A2:A&Items!B2:B))*(LEN(Items!C2:C)),
Items!A2:A&Items!B2:B&"♦"&Items!C2:C, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(Items!A2:A&Items!B2:B))*(LEN(Items!C2:C)),
Items!A2:A&Items!B2:B&"♦♥"&Items!C2:C, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)))
Thank you for that enormous formula! And to think I was trying to accomplish this using a simple FILTER. Would this be the appropriate modification to include another column (column C) in the search criteria?
=ARRAYFORMULA(IFERROR(VLOOKUP('task-itemAssociationsDV'!A2:A&'task-itemAssociationsDV'!B2:B&'task-itemAssociationsDV'!C2:C,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(taskData!A2:A&taskData!B2:B&taskData!C2:C))*(LEN(taskData!D2:D)),
taskData!A2:A&taskData!B2:B&taskData!C2:C&"♦"&taskData!D2:D, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(taskData!A2:A&taskData!B2:B&taskData!C2:C))*(LEN(taskData!D2:D)),
taskData!A2:A&taskData!B2:B&taskData!C2:C&"♦"&taskData!D2:D, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(taskData!A2:A&taskData!B2:B&taskData!C2:C))*(LEN(taskData!D2:D)),
taskData!A2:A&taskData!B2:B&taskData!C2:C&"♦♥"&taskData!D2:D, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)))

Transpose Unique Values from Multiple Columns

I'm trying to generate unique values in D1:F but my formula is not working. For example, row 1 has
A B C
milk milk 44
the output should be:
D E
milk 44
here is my formula and my sheet
=ARRAYFORMULA(unique(A1:C))
UNIQUE works only in one dimension (row or column)
=QUERY(UNIQUE({A:A;B:B;C:C}), "where Col1 is not null", 0)
=ARRAYFORMULA(SPLIT(REGEXREPLACE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE({QUERY(QUERY(
UNIQUE(SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(LEN(A2:A), "♠"&A2:A&"♦"&B2:D, )),,999^99)),,999^99)), "♠")), "♦")),
"select Col1, count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),
"select Col1 offset 1",0),
IF(QUERY(QUERY(UNIQUE(SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(LEN(A2:A), "♠"&A2:A&"♦"&B2:D, )),,999^99)),,999^99)), "♠")), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0), "offset 1",0)<>"",
QUERY(QUERY(UNIQUE(SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(LEN(A2:A), "♠"&A2:A&"♦♀"&B2:D&",", )),,999^99)),,999^99)), "♠")), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0), "limit 0",1),)})
,,999^99))), ", ♀", ", "), ",$", ), "♀"))

Turning formula into ArrayFormula Part2

Following on from this question
Turning formula into ArrayFormula
I failed to make it clear that the value cells may also contain multiple values in CSV format. I tried adjusting it to:
=ARRAYFORMULA(IF(LEN(A4:A), IFERROR(VLOOKUP(SPLIT(A4:A,","),
QUERY(TRIM(TRANSPOSE(SPLIT($B$1, ","))),
"select Col1,count(Col1) group by Col1", 0), 2, 0), 0), ))
But no luck. The test sheet is here.
https://docs.google.com/spreadsheets/d/12xATTwuc-e6kXn_OF2Uibg6EgtSGbInI6Q_-vueknXg/edit#gid=0
My original formula is in B4 which works but needs copying down which is what I want to avoid.
=ARRAYFORMULA(IFERROR(VLOOKUP(A4:A, QUERY({QUERY(TRIM(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(A4:A), "♠"&A4:A&"♦"&TRIM(IFERROR(
SPLIT(A4:A, ","))), )), , 999^99)), , 999^99), "♠")), "♦")), "select Col1", 0),
ARRAY_CONSTRAIN(IFERROR(VLOOKUP(QUERY(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(
QUERY(TRANSPOSE(IF(LEN(A4:A), "♠"&A4:A&"♦"&TRIM(IFERROR(SPLIT(A4:A, ","))), ))
, , 999^99)), , 999^99), "♠")), "♦")), "select Col2", 0), QUERY(IFERROR(VLOOKUP(
QUERY(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(A4:A),
"♠"&A4:A&"♦"&TRIM(IFERROR(SPLIT(A4:A, ","))), )), , 999^99)), , 999^99), "♠")), "♦")),
"select Col2", 0), QUERY(TRIM(TRANSPOSE(SPLIT(B1, ","))),
"select Col1,count(Col1) group by Col1", 0), {1, 2}, 0)),
"select Col1,sum(Col2) group by Col1", 0), 2, 0), 0), COUNTA(QUERY(TRIM(SPLIT(
TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(A4:A),
"♠"&A4:A&"♦"&TRIM(IFERROR(SPLIT(A4:A, ","))), )), , 999^99)), , 999^99), "♠")), "♦")),
"select Col1", 0)), 1)}, "select Col1,sum(Col2) group by Col1" ,0), 2, 0)))

Resources