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
matthewtjy
Helper I
Helper I

Cumulative Distinct Count by Year

Hi, I've used the measure "Measure = CALCULATE(DISTINCTCOUNT(DATA TO COUNT),FILTER(ALLSELECTED(DATA_TABLE),(DATA DATE)<=MAX(DATA_DATE)))" to plot a cumulative graph.

 

For example's sake, I've simplied my data as follows:

DATAYEAR
A2000
B2001
B2001
C2002
C2002
C2002
D2003
D2003
D2003
D2003

 

Plotting the above data with the measure, I get a cumulative graph showing the following results: 2000=1; 2001=2; 2003=3; 2004=4.

 

But when I apply a date filter e.g. last 2 years (2003 and 2004), the results end up showing a graph with 2003=1 and 2004=2, instead of 2003=3 and 2004=4. It's like the graph excluded all data before 2003.

 

Is there anyway to fix it so that when i set a date range filter or drill down the data, it still includes all data before 2003, but just displays years 2003 and 2004?

 

Thanks in advance!

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@matthewtjy 

Sorry, had wrong braces. Try:

Measure = CALCULATE(DISTINCTCOUNT([Data Column]),FILTER(ALL(Table),[Year Column]<=MAX([Year Column])&& [COLOR]<>"BLUE"))

 

 

Paul 

 

 

View solution in original post

12 REPLIES 12
V-pazhen-msft
Community Support
Community Support

@matthewtjy 

 

Yes, correct😀. Just add other filters with AND (&&).

 

Paul 

Hi Paul,

 

Pertaining to this measure, is it possible to have a SUM of 2 measures (Measure1 & Measure 2) and both measures are from 2 different tables and i am unable to combine both tables into 1

 

e.g. Measure1 = CALCULATE(DISTINCTCOUNT([Data Column]),FILTER(ALL(Table1),[Year Column]<=MAX([Year Column])&& [COLOR]<>"BLUE"&& [MATERIAL]<>"Plastic"))

 

Measure2 = CALCULATE(DISTINCTCOUNT([Data Column]),FILTER(ALL(Table2),[Year Column]<=MAX([Year Column])&& [COLOR]<>"BLUE"&& [MATERIAL]<>"Plastic"))

Thanks Paul!

V-pazhen-msft
Community Support
Community Support

@matthewtjy 

Sorry, had wrong braces. Try:

Measure = CALCULATE(DISTINCTCOUNT([Data Column]),FILTER(ALL(Table),[Year Column]<=MAX([Year Column])&& [COLOR]<>"BLUE"))

 

 

Paul 

 

 

Thank Paul! This works like a charm!

 

Just to check, if i need to include extra filters e.g. "Material" is not "Plastic", i could just add on a filter as such correct?

 

Measure = CALCULATE(DISTINCTCOUNT([Data Column]),FILTER(ALL(Table),[Year Column]<=MAX([Year Column])&& [COLOR]<>"BLUE"&& [MATERIAL]<>"Plastic"))

V-pazhen-msft
Community Support
Community Support

@matthewtjy 

 

Try add the color filter inside the running total expression.

Measure = CALCULATE(DISTINCTCOUNT(DATA TO COUNT),FILTER(ALL(DATA_TABLE),[DATA DATE]<=MAX(DATA_DATE) && [COLOR]<>"BLUE"))

 

 

Paul Zheng _ Community Support Team

This formula gives the error "The MAX function only accepts a column reference as an argument"

 

Is there another workaround to this?

 

Thanks in advance!

V-pazhen-msft
Community Support
Community Support

@matthewtjy 

Then try add another filter outside the running total expression.

Measure = CALCULATE(DISTINCTCOUNT(DATA TO COUNT),FILTER(ALL(DATA_TABLE),(DATA DATE)<=MAX(DATA_DATE)), FiLTER(DATA_TABLE, [COLOR]<>"BLUE"))

 

 

Paul Zheng _ Community Support Team

I've tried the DAX measure you shared but i've ended up without a cumulative graph now like in the attached photo (refer to blue graph line). Did I do something wrong?image001.png

V-pazhen-msft
Community Support
Community Support

@matthewtjy 

If you want to ignore the date filter. Try replace the ALLSELECTED() to ALL(). 

Measure = CALCULATE(DISTINCTCOUNT(DATA TO COUNT),FILTER(ALL(DATA_TABLE),(DATA DATE)<=MAX(DATA_DATE)))

 

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

Unfortunately this doesn't work as I have to apply additional filters to the visualisation. Is there a way to include an additional filter to your formula for example to exclude "Blue" in another column called "Colour"?

matthewtjy
Helper I
Helper I

Hi, hope someone would be able to help out, have included screenshots below for further explanation.

 

Based on all my data since 2014, the cumulative count for the blue line is 903 as of May 2021 (see first picture).

 

However, once i filter the results to show the last 13 months, the blue line only shows 227 as of May 2021 (see second picture).

 

Is there a way to show the cumulative count to count since 2014 even with the silcer to only show last 13 months?

 

Thanks!original.jpglast 13 months.jpg

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.