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
data_guy
Regular Visitor

How can I use DISTINCTCOUNT with two filters?

I want to do a distinct count of accounts active in the last year and a half that are not closed. I'm thinking of something like this. Will this work or am I missing something?

 

CALCULATE(
    DISTINCTCOUNT([DimAccountKey]),
    DATESINPERIOD (DimDate[DateKey], MAX (DimDate[DateKey]), -18, MONTH ),
    'DimAccount'[IsClosed]=FALSE()
)

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @data_guy 

 

You can try the following methods.

Measure =
CALCULATE (
    DISTINCTCOUNT ( [DimAccountKey] ),
    DATESINPERIOD ( DimDate[DateKey], MAX ( DimDate[DateKey] ), -18, MONTH ),
    FILTER ( ALL ( 'DimAccount' ), [IsClosed] = FALSE () )
)

Or

Measure =
CALCULATE (
    DISTINCTCOUNT ( [DimAccountKey] ),
    FILTER (
        ALL ( DimDate ),
        DATESINPERIOD ( DimDate[DateKey], MAX ( DimDate[DateKey] ), -18, MONTH )
    ),
    FILTER ( ALL ( 'DimAccount' ), [IsClosed] = FALSE () )
)

 If the desired results are not obtained, can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures.

 

Best Regards,

Community Support Team _Charlotte

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

View solution in original post

3 REPLIES 3
data_guy
Regular Visitor

While the accepted solution from v-zhangti does work, I ended up changing the metric in SQL Server so that I only had to filter using DAX for the DATESINPERIOD. Thank you.

v-zhangti
Community Support
Community Support

Hi, @data_guy 

 

You can try the following methods.

Measure =
CALCULATE (
    DISTINCTCOUNT ( [DimAccountKey] ),
    DATESINPERIOD ( DimDate[DateKey], MAX ( DimDate[DateKey] ), -18, MONTH ),
    FILTER ( ALL ( 'DimAccount' ), [IsClosed] = FALSE () )
)

Or

Measure =
CALCULATE (
    DISTINCTCOUNT ( [DimAccountKey] ),
    FILTER (
        ALL ( DimDate ),
        DATESINPERIOD ( DimDate[DateKey], MAX ( DimDate[DateKey] ), -18, MONTH )
    ),
    FILTER ( ALL ( 'DimAccount' ), [IsClosed] = FALSE () )
)

 If the desired results are not obtained, can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures.

 

Best Regards,

Community Support Team _Charlotte

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

FreemanZ
Super User
Super User

hi @data_guy 

it shall work if the tables are related properly.

Just try and let us know.

If it fails, pls tell us how are the tables related with each other.

Helpful resources

Announcements
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!

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.