Google Sheets Pivot data with multiple columns - google-sheets

I'm trying to get my set of data to be pivot without using pivot table
(https://i.stack.imgur.com/H0BLJ.png)
(https://i.stack.imgur.com/3HDtB.png)

Added Solution to your sheet
formula in cell K13:
={ArrayFormula(IF(COUNTIFS({QUERY({{C2,B2};SORT({C3:C7,B3:B7},1,1,2,1)},"Select Col1")},{QUERY({{C2,B2};SORT({C3:C7,B3:B7},1,1,2,1)},"Select Col1")},ROW(A2:A7),"<="&ROW(A2:A7))>1,,{QUERY({{C2,B2};SORT({C3:C7,B3:B7},1,1,2,1)},"Select Col1")})),QUERY(SORT({{C2:C7},{B2:B7},{"Q4 2022";BYROW(filter(D3:I7,REGEXMATCH(to_TEXT(MONTH(D2:I2)),"^10$|^11$|^12$")),LAMBDA(ax,sum(ax)))},{"Q1 2023";BYROW(filter(D3:I7,REGEXMATCH(to_TEXT(MONTH(D2:I2)),"^1$|^2$|^3$")),LAMBDA(ax,sum(ax)))}},1,1,2,1),"Select Col2, Col3, Col4")}
-

Related

GoogleSheets SumIFS in array formula

I'm trying to convert my Sumifs formula into an array formula
(so that the sheet auto updates)
I'm struggling to do so though
I tried using sumif formula and combining the columns, but I can't get it to work right.
I created this simplified version of my data
https://docs.google.com/spreadsheets/d/1qnoY_MZTup8XLLWCu61-Ifiv8dak6QRc1CxsGKpmFWE/edit?usp=sharing
(I know there's only two rows, but in my actual data there's a lot more and the number of brands vary)
I've shown in column C on sheet 2 how the sumifs formula works.
But ideally I'd like an array formula in cell B2 that will populate all the rows for me (instead of having to fill down the sumifs each time)
No need to use arrayformula for this. You can simply use query:
Formula (A2):
=query({Sheet1!A2:D}, "select Col1, sum(Col4) where Col1 is not null and Col2 is null and Col3 is null group by Col1 label sum(Col4) ''")
This will populate both A and B.
Output:

How to append 3 tables with different number of columns in google sheet?

Hi everyone,
I have 3 tables with different number of columns where some columns are actually repeated in these 3 tables (as shown in the screenshot above).
Table 1: Col A to Col D
Table 2: Col F to Col H
Table 3: Col J to Col L
I want to merge these 3 tables together to reduce the number of columns in my google sheet. The screenshot below is how I process these 3 tables before merging.
I'm using QUERY to create extra columns for each table so that the number of columns and the position are aligned between 3 tables. After that, I use QUERY again to append the 3 processed tables as shown in the screenshot below:
However, this method is very tedious when I have 10 tables or more. Is there any other easier ways or tricks to use so that I can achieve the same expected output as shown in the 3rd screenshot?
This is my sheet:
https://docs.google.com/spreadsheets/d/1H1gJAhp1RVax2fy8D-uEtFxdjb-zAHutkPFv5WZT_TY/edit#gid=0
Any help will be greatly appreciated!
You would need a really complicated formula to get the desired output which is a combination of multiple formula's
I added a new tab in you Google Sheet called "Solution" with this formula included
=QUERY(ARRAYFORMULA({
IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!B3:D3&"~"&Sheet1!A4:A&"~"&Sheet1!B4:D),"~")),"");
IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!G3:H3&"~"&Sheet1!F4:F&"~"&Sheet1!G4:H),"~")),"");
IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!K3:L3&"~"&Sheet1!J4:J&"~"&Sheet1!K4:L),"~")),"")}),
"SELECT Col2, SUM(Col3) WHERE Col2 is not null GROUP BY Col2 PIVOT Col1 LABEL Col2 'Student Name' ")
Steps:
Unpivot each table =IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!B3:D3&"~"&Sheet1!A4:A6&"~"&Sheet1!B4:D6),"~")),"")
Combine all tables into one table: =ARRAYFORMULA({__Unpivot1__; __Unpivot2__, __Unpivot3__})
Pivot above data in Step2: =Query(__Step2__, "SELECT Col2, SUM(Col3) GROUP BY Col2 PIVOT Col1 LABEL Col2 'Student Name' ")
Add WHERE Col2 is not null in the query to remove any possible blank rows

How to count records based on subset of data in googlesheet?

I have a table of tickets assigned to users. The tickets are either in Open, Closed or Resolved state.
I'm able to create the list of owners using the formula:
=UNIQUE(D9:D20)
I'm also able to generate the number of total issues against each user using the formula:
=COUNTIF(D9:D20, A2)
But now I need to calculate the number of Open, Closed or Resolved issues for each individual users.
Any suggestions please?
=QUERY(C8:D,"select D,COUNT(D) where D<>'' group by D pivot C order by COUNT(D) desc",1)
then just make a totals column to the right of the three statuses and do a SUM() of each row
You may want to consider using this formula:
={{query({C1:D, C1:C},"Select Col2, count(Col1)
where Col2 is not null
group by Col2
pivot Col3 limit 0",1),"Total Issues"};
query(query({C1:D, C1:C},"Select Col2, count(Col1)
where Col2 is not null
group by Col2
pivot Col3",1),"Select Col1 offset 1",0),
ARRAYFORMULA(N(query(query({C1:D, C1:C},"Select Col2, count(Col1)
where Col2 is not null
group by Col2
pivot Col3",1),"Select Col2, Col3, Col4 offset 1",0))),
query(query({C1:D, C1:C},"Select Col2, count(Col1)
where Col2 is not null
group by Col2",1),"Select Col2 offset 1",0)}
Output:
Additional Reference:
Replace Blank Cells with 0 in Query Pivot in Google Sheets
The easiest way to do this is to create a pivot table.
I've got my final version set up like this...
Steps:
Delete the current summary table you have above your data table. Columns A:D can only contain data and the column headers.
Select columns A:D
Data > Pivot table - Existing sheet - Sheet1!F1
In the Pivot table editor panel on the right...
Rows - Add - Owner
Columns - Add - Status
Values - Add - Ticket # - Summarize by - COUNT
Filters - Add - Owner - Status - Uncheck (Blanks)
You can tweak it from there. As you add data to the bottom of the table, it will automatically update the pivot table. NOTE: If you add a new owner, you will need to update the Filter and place a check beside their name.

How to create a Google Spreadsheet pivot table from multiple sheets?

Is it possible to create a pivot table that consolidates data from multiple sheets?
no, it's not. first, you will need to gather your data from all sheets with a query and then create your pivot table:
=QUERY({Sheet1!A:Z; Sheet2!A:Z; Shet3!A:Z}, "select * where Col1 is not null", 0)

Query and Import Range: values firm a few first rows are being merged

I am using this formula to import select columns from one Google Sheet to another:
=QUERY(IMPORTRANGE("1Y06zLsfEBPL8txxc6V0K6544iNjnNDGRYcKHtdixrOg","Reporting!A:S"),"select Col1, Col3, Col4, Col6, Col7, Col19")
Does anyone know why the values in the First and Second row of the columns are being merged automatically?
Ex: If A1 = "Socks" and A2 = "Hats" in the parent Google Sheet, then cell A1 in the imported range Google Sheet would be = "Socks Hats". Other than the first two rows, everything else looks good.
I think yor problem is data with empty cells, query formula can't automatically detect the header of your table. Try this:
=QUERY(IMPORTRANGE("1Y06zLsfEBPL8txxc6V0K6544iNjnNDGRYcKHtdixrOg","Reporting!A:S"),"select Col1, Col3, Col4, Col6, Col7, Col19", 1)

Resources