Related
So I'm wondering why when I add an extra two parameters (one on each function) that I get an Array literal error. Below is the function that runs perfectly fine.
={QUERY(IMPORTRANGE("url", "INVENTORY!$A:$Z"),
"SELECT Col1,Col2,Col3,Col4,Col5,Col15,Col17,Col18,Col7,Col11,Col12,Col13,Col14,Col21 WHERE Col15 IS NOT NULL
AND Col15 < "&F1&"
AND Col19 <> 'Printed'
AND Col20 = 'Restock'
ORDER BY Col15 ASC", 1);
QUERY(IMPORTRANGE("url", "PREINVENTORY!$A:$Z"),
"SELECT Col1,Col2,Col3,Col4,Col5,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,Col19 WHERE Col19 <> 'FBA' AND Col17 = 1 AND Col7 IS NULL",0)}
When I add an extra parameters the sheet breaks and I get the array literal error suggesting I has mismatched columns sizes.
={QUERY(IMPORTRANGE("url", "INVENTORY!$A:$Z"),
"SELECT Col1,Col2,Col3,Col4,Col5,Col15,Col17,Col18,Col7,Col11,Col12,Col13,Col14,Col21 WHERE Col15 IS NOT NULL
AND Col15 < "&F1&"
AND Col19 <> 'Printed'
AND Col20 = 'Restock'
AND Col22 = 1
ORDER BY Col15 ASC", 1);
QUERY(IMPORTRANGE("url", "PREINVENTORY!$A:$Z"),
"SELECT Col1,Col2,Col3,Col4,Col5,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,Col19 WHERE Col19 <> 'FBA' AND Col17 = 1 AND Col7 IS NULL AND Col22 = 1",0)}
Most probably one of your qyeries results in #N/A. Try accounting for that with IFNA like this:
={
IFNA(
QUERY(
IMPORTRANGE("url", "INVENTORY!$A:$Z"),
"SELECT Col1, Col2, Col3, Col4,
Col5, Col15, Col17, Col18,
Col7, Col11, Col12, Col13,
Col14, Col21
WHERE Col15 IS NOT NULL
AND Col15 < " & F1 & "
AND Col19 <> 'Printed'
AND Col20 = 'Restock'
AND Col22 = 1
ORDER BY Col15",
1
),
{"Query returned nothing", SPLIT(REPT(",", 12), ",",,)}
);
IFNA(
QUERY(
IMPORTRANGE("url", "PREINVENTORY!$A:$Z"),
"SELECT Col1, Col2, Col3, Col4,
Col5, Col8, Col9, Col10,
Col11, Col12, Col13, Col14,
Col15, Col19
WHERE Col19 <> 'FBA'
AND Col17 = 1
AND Col7 IS NULL
AND Col22 = 1",
0
),
{"Query returned nothing", SPLIT(REPT(",", 12), ",",,)}
)
}
I have a QUERY that looks up values from various separate sheets, this is its input:
=QUERY( {
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col2, Col4, Col5 where Col1 IS NOT NULL and Col4 IS NOT NULL", 0), { "","","","","" } );
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col6, Col8, Col9 where Col1 IS NOT NULL and Col8 IS NOT NULL", 0), { "","","","","" } );
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col10, Col12, Col13 where Col1 IS NOT NULL and Col12 IS NOT NULL", 0), { "","","","","" } );
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col14, Col16, Col17 where Col1 IS NOT NULL and Col16 IS NOT NULL", 0), { "","","","","" } );
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col18, Col20, Col21 where Col1 IS NOT NULL and Col20 IS NOT NULL", 0), { "","","","","" } )
}, "SELECT * WHERE Col1 IS NOT NULL ORDER BY Col1")
The {} gets repetitive and longwinded, and requires manually updating every time I add another week.
Recently I discovered I can generate a list of Week sheet names using this formula:
=ARRAYFORMULA(
"Week " &
{1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30}
& "!A2:Z133"
)
and then in another column list only those sheets that actually exist:
=IF(
ISERROR(CELL("address",INDIRECT($U2))),
"",
$U2
)
Now I have a column with values such as Week1!A2:Z133, Week2!A2:Z133, etc. How can I use this column to create the QUERY formula source automatically?
Using this formula gets me the first range referenced but none of the subsequent ones in the column:
={ARRAYFORMULA(INDIRECT(AA:AA) )}
Here within this sheet is a basic script for combining tabs that start with the word "Week".
function tabCombo(){
var ss = SpreadsheetApp.getActive();
//Filters sheets to just the ones that start with "Week"
var sheets = ss.getSheets().filter(function (e){return e.getName().slice(0,4)=='Week'});
//combines all tab values into one array and filters out the rows with a certain value in the first column
var combo = sheets.map(e=>e.getDataRange().getValues()).flat().filter(e=>e[0]!='Header1');
//writes that new value to a 'Master' tab.
ss.getRange('Master!A2').offset(0,0,combo.length,combo[0].length).setValues(combo);
}
Take note of the word "Week" which is how it decides which tabs to grab.
Take note of the number 4 (which is how many letters "Week" has)
Take note of the range "Master!A2" which is the top left corner of where the combined data should go.
Take note of the term "Header1" which is how the combined array filters out the header rows from all the tabs.
I'm using a query function with importrange but I need a personalized message when query couldn't find anything in the database. Currently I'm using this formula.
=QUERY(
{
IMPORTRANGE("url", "'Parte 1'!A1:AH");
IMPORTRANGE("url", "'Parte 2'!A1:AH");
IMPORTRANGE("url", "'Parte 3'!A1:AH");
IMPORTRANGE("url", "'Parte 4'!A1:AH")
}, "Select Col2, Col1, Col34, Col24, Col3, Col4, Col5, Col6, Col11, Col7, Col8,
Col9, Col10, Col12, Col13, Col14, Col15, Col20, Col21, Col22, Col23
Where Col10="&$C$1&" And Col22 != 'Duplicado'")
try:
=ARRAYFORMULA(QUERY({
IFERROR(IMPORTRANGE("url", "'Parte 1'!A1:AH"),
{"1 not working", SUBSTITUTE(COLUMN(B:AH)^0, 1, )});
IFERROR(IMPORTRANGE("url", "'Parte 2'!A1:AH"),
{"2 not working", SUBSTITUTE(COLUMN(B:AH)^0, 1, )});
IFERROR(IMPORTRANGE("url", "'Parte 3'!A1:AH"),
{"3 not working", SUBSTITUTE(COLUMN(B:AH)^0, 1, )});
IFERROR(IMPORTRANGE("url", "'Parte 4'!A1:AH"),
{"4 not working", SUBSTITUTE(COLUMN(B:AH)^0, 1, )})},
"select Col2,Col1,Col34,Col24,Col3,Col4,Col5,Col6,Col11,Col7,Col8,
Col9,Col10,Col12,Col13,Col14,Col15,Col20,Col21,Col22,Col23
where Col10="&$C$1&"
and Col22 != 'Duplicado'
or Col1 contains 'not working'"))
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))), ", ♀", ", "), ",$", ), "♀"))
I have the following data format in Google Sheets:
I want to extract out the Quantity column into 2 separate columns based on if the Ready flag is Y or N. The Item Name and Size would be the group By columns, along with the Ready flag. Below is the data format I would like after the query runs:
Have not tried any solutions yet, as I have been out of the programming loop for a long time and am super rusty with SQL.
={"Item name", "Size", "Not ready", "Ready";
{QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1, Col2", 0),
ARRAYFORMULA(ARRAY_CONSTRAIN(IFERROR(VLOOKUP(QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1", 0)&
QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col2", 0),
QUERY(QUERY({A2:A&B2:B, C2:D},
"select *", 0),
"select Col1, Col2, Col3
where Col3='N'", 0), 2, 0), 0),
COUNTA(QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1,Col2", 0))/2, 1)),
ARRAYFORMULA(ARRAY_CONSTRAIN(IFERROR(VLOOKUP(QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1", 0)&
QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col2", 0),
QUERY(QUERY({A2:A&B2:B, C2:D},
"select *", 0),
"select Col1, Col2, Col3
where Col3='Y'", 0), 2, 0), 0),
COUNTA(QUERY(QUERY(QUERY(A2:D,
"select *", 0),
"select Col1, Col2, count(Col1)
where Col2 is not null
group by Col1, Col2
order by Col1 desc
label count(Col1)''", 0),
"select Col1,Col2", 0))/2, 1))}}
=ARRAYFORMULA(IF(NOT(ISBLANK(QUERY(QUERY(A1:D,
"select *", 1),
"select Col1, Col2, sum(Col3)
where Col1 <> ''
group by Col1, Col2
pivot Col4
order by Col1 desc", 1))),
QUERY(QUERY(QUERY(A1:D,
"select *", 1),
"select Col1, Col2, sum(Col3)
where Col1 <> ''
group by Col1, Col2
pivot Col4
order by Col1 desc", 1),
"select *
label Col3 'Not ready', Col4 'Ready'", 1), 0))
You could also do it as pivot table - works fairly well. Item name and size are entered as rows, Ready? as columns and sum(Quantity) as value.
Or indeed as a pivot query
=QUERY(A:D,"SELECT A,B,sum(C) where A<>'' group by A,B pivot D ")