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
Quiny_Harl
Advocate III
Advocate III

Cumulative total measure works with count but doesn't work with distinct count

Hello,

 

I have the following measure to calculate the cumulative total of user IDs for each date:

 

Cumulative Total ID =
VAR MaxDate = MAX('Date'[date])
RETURN
CALCULATE(COUNT(table2[user_id]),FILTER(ALLSELECTED('Date'),'Date'[date]<=MaxDate))
 
It works just as expected:
Quiny_Harl_0-1623668724492.png

However, when I use exactly the same measure to calculate the cumulative total for distinct user IDs, only replacing the COUNT with DISTINCTCOUNT, the result is not correct:

 

Cumulative Total Distinct IDs =
VAR MaxDate = MAX('Date'[date])
RETURN
CALCULATE(DISTINCTCOUNT(table2[user_id]),FILTER(ALLSELECTED('Date'),'Date'[date]<=MaxDate))

 

Quiny_Harl_1-1623669007226.png
What could be the reason for that and how can I fix it?
 
4 REPLIES 4
Anonymous
Not applicable

Hi  @Quiny_Harl ,

You can modify the formula like this:

VAR MaxDate = MAX('Date'[date])
RETURN
CALCULATE(DISTINCTCOUNT(table2[user_id]),FILTER(ALLSELECTED('Date'),'Date'[date]<=MaxDate && 'table2[user_id]=max('table2[user_id])))

 

Best Regards,

Liu Yang

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

Thank you for the suggestion!
The formula cannot work because the last argument of the filter statement, which is 'table2[user_id]=max('table2[user_id]), uses a column which does not belong to the specified table, which is ALLSELECTED['Date']

amitchandak
Super User
Super User

@Quiny_Harl , Try like

 

Cumulative Total Distinct IDs =
VAR MaxDate = MAX('Date'[date])
RETURN
CALCULATE(Sumx(values('Date'[date]), calculate(DISTINCTCOUNT(table2[user_id]))),FILTER(ALLSELECTED('Date'),'Date'[date]<=MaxDate))

 

 

or for each level

 

Cumulative Total Distinct IDs =
VAR MaxDate = MAX('Date'[date])
RETURN
CALCULATE(Sumx(values('Date'[date]), calculate(DISTINCTCOUNT(table2[user_id]))),FILTER(ALLSELECTED('Date'),'Date'[date]<=MaxDate))

 

or

 

Cumulative Total Distinct IDs =
VAR MaxDate = MAX('Date'[date])
RETURN
CALCULATE(Sumx(values('Date'[Year]), calculate(DISTINCTCOUNT(table2[user_id]))),FILTER(ALLSELECTED('Date'),'Date'[date]<=MaxDate))

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

@amitchandak Thank you for your help!
The last one works for the Year level of the date. However, it is necessery for the user to be able to drill down to quarter, month and date level and in this case the measure doesn't give correct results. Any idea?

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