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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
oliverblane72
Frequent Visitor

Cumulative Distinct Count by Day Behaving Incorrectly with Filters

Hi there, I am trying to plot a cumulative distinct count graph of IDs from this table:

oliverblane72_0-1626969296139.png

I used the following DAX code to generate a cumulative distinct count table by date:

CumTable = SELECTCOLUMNS(
DISTINCT('Learner Info Daily'[Created Date]),
"Date", 'Learner Info Daily'[Created Date],
"CumUsers", CALCULATE(DISTINCTCOUNT('Learner Info Daily'[ID]), FILTER(ALLSELECTED('Learner Info Daily'), 'Learner Info Daily'[Created Date] <= EARLIER('Learner Info Daily'[created date]))
)
)

Which looks like:

oliverblane72_1-1626969421534.png

 

However, plotting this with slicers on "Location" does not behave as expected - the cumulative distinct count is the same for each location, the only difference being the x axis (since the dates at which certain locations started getting IDs was different for each):

oliverblane72_2-1626969507565.pngoliverblane72_3-1626969523941.png

The only relationship between the two tables is on the date column. I am confused as to where it is going wrong.

 

I appreciate any help on this - thank you!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

 

// Please create a proper calendar in your
// model following the guidelines outlined here:
// https://dax.guide/dateadd
// and connect it to your fact table and remember
// that fact tables should always be hidden and
// slicing should only happen via dimensions. If
// you want to get into trouble, ignore the rule.
//
// Then you can write:

[# Distinct ID to Date] =
var CurrentDate = MAX( Dates[Date] )
return
	CALCULATE(
		DISTINCTCOUNT( 'Learner Info Daily'[LRN] ),
		KEEPFILTERS( Dates[Date] <= CurrentDate ),
		ALLSELECTED( Dates )
	)

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

 

 

// Please create a proper calendar in your
// model following the guidelines outlined here:
// https://dax.guide/dateadd
// and connect it to your fact table and remember
// that fact tables should always be hidden and
// slicing should only happen via dimensions. If
// you want to get into trouble, ignore the rule.
//
// Then you can write:

[# Distinct ID to Date] =
var CurrentDate = MAX( Dates[Date] )
return
	CALCULATE(
		DISTINCTCOUNT( 'Learner Info Daily'[LRN] ),
		KEEPFILTERS( Dates[Date] <= CurrentDate ),
		ALLSELECTED( Dates )
	)

 

 

Hi there, I cannot thank you enough - your solution works perfectly!

 

One thing I am confused about is why we need ALLSELECTED( Dates ). Apologies if this is a silly question, I am quite new to DAX and Power BI.

 

Many thanks for your help!

Anonymous
Not applicable

Calculated tables are STATIC. Once calculated, they never change. You need a measure, not a table.

Right, I see! Thank you, Daxer.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors