Forum Discussion
james231660
Aug 13, 2024Copper Contributor
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 ...
PeterBartholomew1
Aug 13, 2024Silver 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'.