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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
analytical_mind
Frequent Visitor

Equivalence of doing a pivot table of a pivot table

Hi,

 

So my dataset consists of Customers, Market Category, Year

 

CustomerMarket CategoryYear
AX2022
AY2023
BY2022
DZ2021

 

I want to be able to answer the following questions: how many categories are a unique customer transactioning (but for me it doesn't matter the name of the customer, I want a summary of that): so something like

 

Distinct CategoryNumber of Unique Customers
12 (Customer B + Customer D, they are each transaction in a single [but different] cattegory)
21 (Customer A has 2 different categories)

 

I would achieve this in excel by doing a pivot table, selecting the customer as a row and counting the distinct categories as a Value. Then I would copy this result, paste in another sheet and do another pivot table: this time selecting the distinct category as a row and counting the number of distinct customers.

 

How to achieve this in DAX? I tried using summarizecolumns but when I include the year, the results don't really make sense.

 

SUMMARIZECOLUMNS (
    table[Customer ],
    table[Year],
    "Distinct Category", [Distinct Category] -- this is a measure in my original table; it is the distinct count of category
)
1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @analytical_mind 

According to your description, you want to create a summary table by dax code .

This is my test data and my understand for your need:

vyueyunzhmsft_0-1688612375571.png

We can click "New Table"  to create the calculated table :

Table 2 = var _t =  SUMMARIZE('Table','Table'[Customer],'Table'[Year] , "Distinct Category", DISTINCTCOUNT('Table'[Market Category]))

return
SUMMARIZE(_t , [Distinct Category] , [Year] , "Number of Unique Customers", DISTINCTCOUNT('Table'[Customer]))
Table 3 = var _t =  SUMMARIZE('Table','Table'[Customer],"Distinct Category",DISTINCTCOUNT('Table'[Market Category]))

return
SUMMARIZE(_t , [Distinct Category] , "Number of Unique Customers" ,  DISTINCTCOUNT('Table'[Customer]))

 

The result is as follows:

vyueyunzhmsft_1-1688612429413.pngvyueyunzhmsft_2-1688612436049.png

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

View solution in original post

3 REPLIES 3
v-yueyunzh-msft
Community Support
Community Support

Hi , @analytical_mind 

According to your description, you want to create a summary table by dax code .

This is my test data and my understand for your need:

vyueyunzhmsft_0-1688612375571.png

We can click "New Table"  to create the calculated table :

Table 2 = var _t =  SUMMARIZE('Table','Table'[Customer],'Table'[Year] , "Distinct Category", DISTINCTCOUNT('Table'[Market Category]))

return
SUMMARIZE(_t , [Distinct Category] , [Year] , "Number of Unique Customers", DISTINCTCOUNT('Table'[Customer]))
Table 3 = var _t =  SUMMARIZE('Table','Table'[Customer],"Distinct Category",DISTINCTCOUNT('Table'[Market Category]))

return
SUMMARIZE(_t , [Distinct Category] , "Number of Unique Customers" ,  DISTINCTCOUNT('Table'[Customer]))

 

The result is as follows:

vyueyunzhmsft_1-1688612429413.pngvyueyunzhmsft_2-1688612436049.png

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

That's exactly what I needed, thanks. But the 'bad' part is that apparently I'll need to manage multiple summarized tables to get different analysis right?

Hi, @analytical_mind 

Yes, If you need to get different values under different dimensions, you really need to create two tables to get.

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors