Google sheet dynamic value pivot table - arrays

I'm trying to get a pivot table, where I can select the values from something like a slicer.
I found out that using GETPIVOTDATA can get the trick with a dropdown list, but not very usefull since it's only 1 cell.

try:
=QUERY({A2:A8, INDIRECT(
ADDRESS(2, MATCH(D10, 1:1, 0))&":"&
ADDRESS(8, MATCH(D10, 1:1, 0)))},
"select Col1,sum(Col2)
where Col1 is not null
group by Col1
label sum(Col2)''", 0)

Related

Google Sheets - Flattening a table into two columns, but returning results based on varying conditions

My table has data similar to the following:
Raw Data
I am flattening the data into two columns using the following:
=INDEX(QUERY(SPLIT(FLATTEN(IF(SheetName!B1:D=TRUE, SheetName!B1:D1&"×"&SheetName!A1:A,)), "×"),"where Col2 is not null order by Col1 asc"))
The result is depicted here:
Flattened Data
However, I also need to return within the "flattened data" columns the following:
1#email.com | 1#email.com
2#email.com | 2#email.com
3#email.com | 3#email.com
In other words, I need to return SheetName!A1:A&"×"&SheetName!A1:A for each email address contained in the email column (Column A), in addition to the other data that is being flattened into the column. I have tried variations using IF/IFS statements, wildcards (not permitted within IFs), etc. However, I am now seeking some help after striking out many times. Thanks for any help you can offer!
Update Example spreadsheet with sample data and current vs. desired results (formula in cell H2):
https://docs.google.com/spreadsheets/d/1wq9kR4UqYeWsqSCbnkGGHbR-TIHTfaBb_ixGk41X2cs/edit?usp=sharing
perhaps:
=INDEX(QUERY(SPLIT(FLATTEN(IF(SheetName!B1:D=TRUE,
SheetName!B1:D1&"×"&SheetName!A1:A&"×"&SheetName!A1:A,)), "×"),
"where Col3 is not null order by Col1 asc"))
update:
=INDEX({QUERY(SPLIT(FLATTEN(
IF(Sheet1!B1:F=TRUE, Sheet1!B1:F1&"×"&Sheet1!A1:A,)), "×"),
"where Col2 is not null order by Col1");
TEXT(UNIQUE(FILTER(A2:A, A2:A<>"")), {"#", "#"})})

Need to Add Values to Certain Items

I have a table that I need to add the same values to a whole bunch of items
(in a nut shell if the item doesn't have a UNIT of "CTN" I want to add the same values i have listed to them all)
I thought the following would work but it doesn't :(
Any idea what i am doing wrong ?
INSERT INTO ICUNIT
(UNIT,AUDTDATE,AUDTTIME,AUDTUSER,AUDTORG,CONVERSION)
VALUES ('CTN','20220509','22513927','ADMIN','AU','1')
WHERE ITEMNO In '0','etc','etc','etc'
If I understand correctly you might want to use INSERT INTO ... SELECT from original table with your condition.
INSERT INTO ICUNIT (UNIT,AUDTDATE,AUDTTIME,AUDTUSER,AUDTORG,CONVERSION)
SELECT 'CTN','20220509','22513927','ADMIN','AU','1'
FROM ICUNIT
WHERE ITEMNO In ('0','etc','etc','etc')
The query you needs starts by selecting the filtered items. So it seems something like below is your starting point
select <?> from dbo.ICUNIT as icu where icu.UNIT <> 'CTN' order by ...;
Notice the use of schema name, terminators, and table aliases - all best practices. I will guess that a given "item" can have multiple rows in this table so long as ICUNIT is unique within ITEMNO. Correct? If so, the above query won't work. So let's try slightly more complicated filtering.
select distinct icu.ITEMNO
from dbo.ICUNIT as icu
where not exists (select * from dbo.ICUNIT as ctns
where ctns.ITEMNO = icu.ITEMNO -- correlating the subquery
and ctns.UNIT = 'CTN')
order by ...;
There are other ways to do that above but that is one common way. That query will produce a resultset of all ITEMNO values in your table that do not already have a row where UNIT is "CTN". If you need to filter that for specific ITEMNO values you simply adjust the WHERE clause. If that works correctly, you can use that with your insert statement to then insert the desired rows.
insert into dbo.ICUNIT (...)
select distinct icu.ITEMNO, 'CTN', '20220509', '22513927', 'ADMIN', 'AU', '1'
from ...
;

Using ArrayFormula with Query or Filter

I have a set of data and I want to filter it on some conditions.
My data goes here(image1):
Similarly, I have another column that has a unique value of A column and it goes like this (image 2):
Now my problem is I am trying to filter my data(image 1) with the name matching in image 2 with one additional condition.
My filter formula works fine but only for the first name in image 2.
I am trying to get output for all the names mentioned in image2 using the Array formula. Here is my formula :
=ARRAYFORMULA(Filter(data!$A2:C,Data!$A2:A='Sheet1'!H2:H,Data!$B2:B="MATCH"))
try:
=INDEX(SPLIT(FLATTEN(QUERY(QUERY({A2:A, B2:B, C2:C},
"select max(Col3)
where Col2 = 'MATCH'
group by Col3
pivot Col1"),,9^9)), " "))

Converting two columns table into one column table in Google Sheets

In column A there is a list of tasks.
In column B each task has an associated group.
How to, using built-in formulas, generate sequence like in column D?
Here is a screenshot :
try:
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(QUERY(IF(A2:B="",,A2:B&"♦"),
"select max(Col1) where Col1 is not null group by Col1 pivot Col2", 0)
,,999^99)),,999^99), "♦"))))
This should work as well as player0s. I keep trying to get him to use FLATTEN() :)
=QUERY(FLATTEN(TRANSPOSE(QUERY(A2:B,"select Max(A) group by A pivot B"))),"where Col1<>''")

Count checked checkboxes within a query

How do I count checked checkboxes within a query in Google sheets (this is part of a group query where I want to count checked checkboxes in column B for each value of column A grouped by column A)?
try:
=ARRAYFORMULA(QUERY({A:A\ B:B*1};
"select Col1,sum(Col2)
where Col1 is not null
group by Col1
label sum(Col2)''"))

Resources