Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

How do I pivot a dimension count while keeping the ID rows?

Hi everyone. 

 

This is what I want to do in Power Query. It's seemlingly very simple but I haven't been able to find the answer. 

 

When I pivot by Product, it gives me the total product count for the whole set. But I want the count grouped by ID, as seen in the image below. 

 

PBIX: https://drive.google.com/file/d/1tgQD-FD9PRQ1okqPZyMW2pXLzKUtMB_5/view?usp=sharing

 

 

ThePiecesFit_0-1714070759769.png

 

Thanks for your time. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @Anonymous 

You can refer to @amitchandak advice, his suggestion does work in Desktop using Matrix to achieve what you need, and if you want to achieve the effect in Power Query, you can refer to the following method.

vyaningymsft_0-1714123285263.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrOyE9VitWBcJwTi+DsgJzEPIRMSFEqghNcWJpZVJSaAxYwghqiAOfBTDFCMcUIXaMxirQxsiXG2NTCXWqCotEEWaMJukYTZI2mSI4zRTHEFG5ILAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [IDs = _t, Product = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"IDs", type text}, {"Product", type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Product", Text.Trim, type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Trimmed Text", "Index", 0, 1, Int64.Type),
    #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[Product]), "Product", "Index", List.NonNullCount)
in
    #"Pivoted Column"

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi, @Anonymous 

You can refer to @amitchandak advice, his suggestion does work in Desktop using Matrix to achieve what you need, and if you want to achieve the effect in Power Query, you can refer to the following method.

vyaningymsft_0-1714123285263.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrOyE9VitWBcJwTi+DsgJzEPIRMSFEqghNcWJpZVJSaAxYwghqiAOfBTDFCMcUIXaMxirQxsiXG2NTCXWqCotEEWaMJukYTZI2mSI4zRTHEFG5ILAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [IDs = _t, Product = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"IDs", type text}, {"Product", type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Product", Text.Trim, type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Trimmed Text", "Index", 0, 1, Int64.Type),
    #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[Product]), "Product", "Index", List.NonNullCount)
in
    #"Pivoted Column"

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

amitchandak
Super User
Super User

@Anonymous , I  matrix visual, put id on row, product on column and count measure in values. it should work

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.