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

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

Reply
Anonymous
Not applicable

DAX syntax for applying a filter before a distinct count

Hi All, 

 

I have been racking my brains with this one, I am trying to write a measure that brings me an accumulative line graph on a fixed date. This will sit inside a visual that is dynamic (eg two more lines that show whichever date is selected). 

 

The problem I seem to have is my formula calculates the distinct count BEFORE it applies the date filter. This results in skewed data being returned.

 

My formula:

"Memphis Original Plan =
CALCULATE(
CALCULATE(
CALCULATE(
DISTINCTCOUNT('Project Plan Table'[PROJECT_PLAN])
),
FILTER('Project Plan Table','Project Plan Table'[QB_Date] = DATE(2020,08,03))
),
ALL('Project Plan Table'[QB_Date]),
FILTER(ALL('Calendar'),'Calendar'[Date] <= MAX('Calendar'[Date]) )
)"

 

I have tried lots of variations but with no success. 

 

Is there something here that I haven't considered?

 

Thank you, 

Ben

3 REPLIES 3
AlB
Community Champion
Community Champion

Hi @Anonymous 

What is the logic for using so many, nested, CALCULATE()s? I'm not sure I understand what you need, perhaps you could explain it a bit more with an example, inlcuding the fields being used in the visual. Would something like this not suffice?

Memphis Original Plan =
CALCULATE (
    DISTINCTCOUNT ( 'Project Plan Table'[PROJECT_PLAN] ),
    FILTER (
        ALL ( 'Calendar'[Date] ),
        'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
    )
)

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Anonymous
Not applicable

hey, @AlB  and @amitchandak,

 

Thank you for coming back to me so quickly. This is quite a large and complex dataset (800Mb ish?) so unlikely I can find a way to trim down for sampling, although the data isn't sensitive so it's not impossible, I will look into it. 

 

Using a long workaround of referencing the table the visual should look like this:

mclintockb1_0-1601889950581.png

Where the slicer represents a timestamp in the programme database, the red must remain the same, the purple and orange change accordingly. 

 

At a push, I can stay with this solution, but I am certain a smoother process can be built. 

 

The nested calculates are an attempt to perform the distinct count before the filter, also where the FILTER(ALL('Calendar'),'Calendar'[Date] <= MAX('Calendar'[Date]) ) places in the code decides whether the line accumulates the total or not. 

amitchandak
Super User
Super User

@Anonymous ,

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Try like

Memphis Original Plan =
CALCULATE(
DISTINCTCOUNT('Project Plan Table'[PROJECT_PLAN]),FILTER(ALLselected('Calendar'),'Calendar'[Date] <= MAX('Calendar'[Date]) )
FILTER('Project Plan Table','Project Plan Table'[QB_Date] <= DATE(2020,08,03))
)

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.