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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
WilliamPH2
Frequent Visitor

Distinct Count Does Not Work In Subtotal Rows

Hi,

 

I’m a newbie in DAX, and am using Excel 2016.

 

I made a dynamic ABC classification for my data using a pattern provided by Gerhard Brueckl on daxpatterns.com (https://www.daxpatterns.com/abc-classification-dynamic/). The pattern is really long, and I understand about 25% of it (if I’m generous) and so the best I can say is to go to the link I provided and download the Excel 2013 sample he provides at the end of the article. (I used the “Basic Pattern File” once I downloaded the folder.)

 

All went well in using his pattern for my data. But then I decided to make a measure to count how many products are in each class. You can add this measure to his sample to get the result:

ABC Count=
IF(NOT(ISBLANK([Sales Amount ABC])), 
DISTINCTCOUNT([ProductModel]),
BLANK())

So once I had my ABC Count measure, I moved “Class” to the Rows field (above the ProductModel) and got the info as you see here, filtered for 2006 (excuse my poor copy-and-paste job. I don’t know how else to show it).

Row LabelsSales Amount ABC
A4,540,036.84
Mountain-200163,927.86
Road-1502,948,494.48
Road-2501,427,614.50
B1,297,712.75
Mountain-200643,381.13
Road-250143,983.13
Mountain-100510,348.49
C692,593.94
Mountain-100244,799.28
Road-550-W146,063.88
Road-650301,730.79
Grand Total6,530,343.53

 

But then I added my ABC Count measure to the values area. Chaos erupts on the subtotal level!

Row LabelsSales Amount ABCABC Count
A4,540,036.84120
Mountain-200163,927.861
Road-1502,948,494.481
Road-2501,427,614.501
B1,297,712.75120
Mountain-200643,381.131
Road-250143,983.131
Mountain-100510,348.491
C692,593.94120
Mountain-100244,799.281
Road-550-W146,063.881
Road-650301,730.791
Grand Total6,530,343.53120

 

I know how to turn off a measure of a subtotal row, using HASONEVALUE or something similar, but how does a person tell a DAX measure that you want a distinct count of only the items that are in the class showing on the subtotal row??

 

For my data it needs to be distinct count, because there’s a whole bunch of rows for every product in the data.

 

Thanks so much for helping out my floundering. Maybe I’m asking something that can’t be done?!

 

I hope not.

 

Thanks again.

 

William

1 ACCEPTED SOLUTION

Sorry I misunderstood your question. Try this measure

 

ABC Count =IF(NOT(HASONEVALUE(Products[ProductModel])),CALCULATE (
DISTINCTCOUNT(Products[ProductModel]),
VALUES ( 'Products'[ProductCode] ),
FILTER (
CALCULATETABLE (
ADDCOLUMNS (
ADDCOLUMNS (
VALUES ( 'Products'[ProductCode] ),
"OuterValue", [Sales Amount]
),
"CumulatedSalesPercentage", DIVIDE (
SUMX (
FILTER (
ADDCOLUMNS (
VALUES ( 'Products'[ProductCode] ),
"InnerValue", [Sales Amount]
),
[InnerValue] >= [OuterValue]
),
[InnerValue]
),
CALCULATE (
[Sales Amount],
VALUES ( 'Products'[ProductCode] )
)
)
),
ALL ( 'Products' )
),
[CumulatedSalesPercentage] > [MinLowerBoundary]
&& [CumulatedSalesPercentage] <= [MaxUpperBoundary]
)
))

View solution in original post

4 REPLIES 4
ChandeepChhabra
Impactful Individual
Impactful Individual

Hi @WilliamPH2,

 

Please revise your ABC Count measure =IF(NOT(ISBLANK([Sales Amount ABC]))&&NOT(HASONEVALUE(Products[ProductModel])),DISTINCTCOUNT(Products[ProductModel]),BLANK())

 

I think this should work as you expected. Here is the snapshot

 

Capture.PNG

 

Hope it helps

Hi Chandeep, thanks for the reply. The problem is, I want the subtotals to be accurate. As of now, they count everything in the data model!

 

 

Sorry I misunderstood your question. Try this measure

 

ABC Count =IF(NOT(HASONEVALUE(Products[ProductModel])),CALCULATE (
DISTINCTCOUNT(Products[ProductModel]),
VALUES ( 'Products'[ProductCode] ),
FILTER (
CALCULATETABLE (
ADDCOLUMNS (
ADDCOLUMNS (
VALUES ( 'Products'[ProductCode] ),
"OuterValue", [Sales Amount]
),
"CumulatedSalesPercentage", DIVIDE (
SUMX (
FILTER (
ADDCOLUMNS (
VALUES ( 'Products'[ProductCode] ),
"InnerValue", [Sales Amount]
),
[InnerValue] >= [OuterValue]
),
[InnerValue]
),
CALCULATE (
[Sales Amount],
VALUES ( 'Products'[ProductCode] )
)
)
),
ALL ( 'Products' )
),
[CumulatedSalesPercentage] > [MinLowerBoundary]
&& [CumulatedSalesPercentage] <= [MaxUpperBoundary]
)
))

Thanks so much for taking the time to help!

 

William

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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