Forum Discussion
How to create a pivot table to represent categorical text?
Hello,
As seen in attached file (hopefully its attached)<
I have a table of 6 products showing the awareness of each product either as "aware", "not aware" or "blank".
I am trying to make a pivot table as seen here
Is there a way to do this as i can only seem to do it for one category at a time rather than all at once. Thanks!
- on Excel PC Version 2405
- Riny_van_EekelenPlatinum Contributor
james231660 First of all you need to get rid of the empty rows in your data range. Then you need to unpivot (flatten) the data so that you end up with one column for Product and one for all the 'scores'. Then you can make a pivot table from that data set. The first two steps can be done in Power Query as demonstrated in the attached file.
- PeterBartholomew1Silver Contributor
I recognise that james231660 's query requires a pivot table solution. Despite that, I chose to examine the problem with a view to using an Excel 365 formula. I could follow Riny_van_Eekelen and flatten the data (TOCOL) before pivoting it (PIVOTBY). However, because array formulas can often work directly with data held as a cross-tab, I reverted to COUNTIFS to perform the conditional aggregation.
= LET( COUNTIFλ, LAMBDA(response, LAMBDA(product, COUNTIFS(product, response))), aware, BYCOL(Table1, COUNTIFλ("Aware")), unaware, BYCOL(Table1, COUNTIFλ("Not Aware")), TRANSPOSE(VSTACK(Table1[#Headers], aware, unaware)) )
I chose to define the Curried Lambda function, COUNTIFλ, rather than using separate LAMBDA/COUNTIFS for 'aware' and 'unaware'.