Append Text to end of Query Results in Google Sheets - google-sheets

Hello I have a function that is running two queries. I would like to add the letter E to the end of the first Query Results and the Letter B to the end of the query results.
My current function is
={QUERY(importRange("*****", "'Inventory'!A3:D"), "SELECT Col2 WHERE ((Col3) > 0)", 1);QUERY(importRange("******", "'Inventory'!A3:D"), "SELECT Col2 WHERE ((Col4) > 0)", 1)}

use:
=ARRAYFORMULA({QUERY(IMPORTRANGE(
"1FpeC9Nck7aGjTEoHg5R0QQBC4S5zj4Yiu_-p0AjvqXY", "'Inventory'!A3:D"),
"select Col2 where Col3 > 0", 1)&"E"; QUERY(IMPORTRANGE(
"1FpeC9Nck7aGjTEoHg5R0QQBC4S5zj4Yiu_-p0AjvqXY", "'Inventory'!A3:D"),
"select Col2 where Col4 > 0", 1)&"B"})

Related

An Arrayformula to Split the given data as shown

Please tell me the Arrayformula at C1 which converts the column A to column C,D & E as shown.
Google Sheet Link
Extra information:
Column A is actually not raw data, it is also an Arrayformula:
=ARRAYFORMULA(VLOOKUP($A:$A, TRIM(SUBSTITUTE(SPLIT(FLATTEN(QUERY(QUERY( {Sheet1!$B:$B&"^"&Sheet1!$C:$C&"^"&Sheet1!$D:$D&"#", Sheet1!$A:$A,Sheet1!$A:$A&"×"}, "select max(Col1) where Col2 is not null group by Col1 pivot Col3",1),,9^9)), "×"), "#", CHAR(10))), 2, 0))
You can check the "Sheet1" & "Extra Information" sheets to understand it.
"Sheet1" Sheet:
"Extra Information" Sheet:
This Arrayformula at B1 is what I achieved, I am not able to split this by ^ into columns as shown in 1st Image.
try in C2:
=ARRAYFORMULA(IFERROR(REGEXREPLACE(REGEXREPLACE({
VLOOKUP(A2:A, TRIM(SPLIT(FLATTEN(QUERY(QUERY({IF(Sheet1!A2:D="",,{Sheet1!A2:A&"♦", Sheet1!B2:D&"♥"}), ROW(Sheet1!A2:A)},
"select max(Col2) where Col2 is not null group by Col5 pivot Col1"),,9^9)), "♦")), 2, ),
VLOOKUP(A2:A, TRIM(SPLIT(FLATTEN(QUERY(QUERY({IF(Sheet1!A2:D="",,{Sheet1!A2:A&"♦", Sheet1!B2:D&"♥"}), ROW(Sheet1!A2:A)},
"select max(Col3) where Col2 is not null group by Col5 pivot Col1"),,9^9)), "♦")), 2, ),
VLOOKUP(A2:A, TRIM(SPLIT(FLATTEN(QUERY(QUERY({IF(Sheet1!A2:D="",,{Sheet1!A2:A&"♦", Sheet1!B2:C&"♥", TEXT(Sheet1!D2:D, "dd/mm/e")&"♥"}), ROW(Sheet1!A2:A)},
"select max(Col4) where Col2 is not null group by Col5 pivot Col1"),,9^9)), "♦")), 2, )}, "♥$", ), "♥ ", CHAR(10))))

Google Sheet Query Pivot - count if a date is between a range of dates

https://docs.google.com/spreadsheets/d/1AQUNPb4d3EqeSZb9SwfzemR7MfSIkMFkDAZ8rPLA3rc/edit?usp=sharing
I have 3 columns :
City
Date start
End date
I want 3 table :
Pivot Table city with people which enter during the year (Done)
=query(QUERY({$A$2:$C$10};
"select Col1, count(Col1)
where year(Col2)=2018 or year(Col2)=2019 or year(Col2)=2020
group by Col1
pivot year(Col2)");
"select * order by Col4 desc, Col3 desc, Col2 desc label Col1 'Start'";1)
Pivot Table city with people which left during the year (Done)
=query(QUERY({$A$2:$C$10};
"select Col1, count(Col1)
where (year(Col3)=2018 or year(Col3)=2019 or year(Col3)=2020)
group by Col1
pivot year(Col3)");
"select * order by Col4 desc, Col3 desc, Col2 desc label Col1 'End'";1)
- Pivot Table city with people which stay during the year (Fail)
=query(QUERY({$A$2:$C$10};
"select Col1, count(Col1)
where
(2018>=YEAR(Col2) and 2018<=YEAR(Col3) or
(2019>=YEAR(Col2) and 2019<=YEAR(Col3) or
(2020>=YEAR(Col2) and 2020<=YEAR(Col3)
group by Col1
pivot year(Col2)");
"select * order by Col4 desc, Col3 desc, Col2 desc label Col1 'Between'";1)
For the last one, i am getting trouble.
I guess my Where condition is not adapted and my pivot not working too.
I know pivot year(Col2) can't work for the last one, because if a row got a date start 2015 and 2020 end start, i want it to be counted, but my pivot won't show up 2018 2019 2020.
Any idea ?
Thanks for your time
use:
=ARRAYFORMULA(QUERY(QUERY(UNIQUE(SPLIT(FLATTEN(IF(DAYS(C2:C10; B2:B10)>=
SEQUENCE(1; 5000; ); ROW(A2:A10)&"×"&A2:A10&"×"&TEXT(B2:B10+SEQUENCE(1; 5000; );
"yyyy-1-1"); )); "×"));
"select Col2,count(Col2)
where year(Col3) matches '2018|2019|2020'
group by Col2
pivot year(Col3)
label Col2'Between'");
"order by Col4 desc, Col3 desc, Col2 desc"))
update:
=ARRAYFORMULA(QUERY(QUERY(SPLIT(FLATTEN(IF(DATEDIF(B2:B; C2:C; "Y")>=
SEQUENCE(1; MAX(DATEDIF(B2:B; C2:C; "Y")); ); ROW(A2:A)&"×"&A2:A&"×"&
YEAR(B2:B)+SEQUENCE(1; MAX(DATEDIF(B2:B; C2:C; "Y")); )&"-1-1"; )); "×");
"select Col2,count(Col2)
where year(Col3) matches '2018|2019|2020'
group by Col2
pivot year(Col3)
label Col2'Between'");
"order by Col4 desc, Col3 desc, Col2 desc"))

Filtering within an "inner value" in Google Sheets

In Google Sheets, it's possible to sort by an "inner value", for example:
Is it also possible to do this in the "Filter" (more accurate, this would be a "having" clause), or is this option only available for sorting?
Here's a copy of an example sheet where I have the data sorted, and I'd also like to do a similar filter: https://docs.google.com/spreadsheets/d/1nfdh93lFcTHQQYB79mXGtz9huvJhvSfqTAw8GMMuEFU/edit#gid=0
=QUERY(QUERY(A:D,
"select A,sum(C) where C >= 2 group by A pivot B"),
"where Col2 is not null")
to mimic those Grand Totals from Pivot table:
=ARRAYFORMULA({{QUERY(QUERY(A:D,
"select A,sum(C) where C >= 2 group by A pivot B"),
"where Col2 is not null"),{"Grand Total";
MMULT(QUERY(QUERY(QUERY(A:D,
"select sum(C) where C >= 2 group by A pivot B"),
"where Col1 is not null"), "offset 1", 0),
ROW(INDIRECT("A1:A"&COUNTUNIQUE(B2:B)))^0)}};{"Grand Total",
TRANSPOSE(MMULT(transpose({QUERY(QUERY(QUERY(A:D,
"select sum(C) where C >= 2 group by A pivot B"),
"where Col1 is not null"), "offset 1", 0),
MMULT(QUERY(QUERY(QUERY(A:D,
"select sum(C) where C >= 2 group by A pivot B"),
"where Col1 is not null"), "offset 1", 0),
ROW(INDIRECT("A1:A"&COUNTUNIQUE(B2:B)))^0)}),
ROW(INDIRECT("A1:A"&COUNTUNIQUE(B2:B)))^0))}})

How to calculate ALL modes in a Google Sheets?

I have a data set (11,11,14,14,10).
My goal is to return all frequently appeared numbers. I used =mode() function.
But, it does not return 11 and 14, only returns 11.
Any ideas/thoughts on that?
With layout as shown,
=query(A2:A6,"select count(A), A group by A order by count(A) desc label count(A) 'frequency'")
should return a listing of all frequencies in descending order:
=QUERY(QUERY(A1:A, "select count(A), A
group by A
order by count(A) desc"),
"select Col2 where Col1 > 1", 0)
=TRANSPOSE(QUERY(QUERY(QUERY(TRANSPOSE(E1:1), "select *"),
"select count(Col1), Col1
group by Col1
order by count(Col1) desc"),
"select Col2 where Col1 > 1", 0))

How to QUERY (ImportRange) if the "where" clause also uses imported values?

I am trying to query ImportRange data by the condition that a column matches a value from the imported spreadsheet, but it does not work:
=Query(importRange("KEY1","namesheet1!A2:R1600"), "select Col4 where Col7 = (importRange("KEY1","namesheet2!F108:F108")) ",0)
Replace
"select Col4 where Col7 = (importRange("KEY1","namesheet2!F108:F108")) "
by
"select Col4 where Col7 = " & importRange("KEY1","namesheet2!F108")

Resources