Search code examples
google-sheetspivot-tableformula

Google Sheets : simple query with pivot clause


I can't find a way to simplify a query to get a similar result to a pivot. Although a pivot table is easy, I would prefer to use a query because I can then personalise headers.

Here's the link with the data :

https://docs.google.com/spreadsheets/d/1R461nv2lD4efpuUuDonFMYGnLH510n7gwpbzG2WAUaw/edit?usp=sharing.

This is the working embedded queries :

= query(query(Data!A1:C, " SELECT B,count(B) WHERE B is not null GROUP BY B,C ORDER BY B ASC "), "SELECT Col1, Count(Col1) group by Col1 LABEL Col1 'Status',Count(Col1) 'Count'",1 )

This is the query I'd like to use with a pivot clause :

=query(Data!A1:C, "Select B, count(C) group by count(C)  Pivot C" ,1)

Here's what I'm looking for : enter image description here


Solution

  • Try

    ={"Status","Count(Categories)";transpose(query(unique(B:C),"select count(Col2) where Col2 is not null pivot Col1",1))}
    

    enter image description here

    or simplier

    =query(unique(B:C),"select Col1, count(Col2) where Col2 is not null group by Col1",1)
    

    enter image description here