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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kotarosai
Helper II
Helper II

DISTINCTCOUNT with multiple filter criteria

Hello, I am having an issue with a measure / formula. One works as intended when using an OR logic but does not work as intended with an AND. Both formulas are below and the measure is shown in the matrix table. Any support is appreciated, thanks!

 

WORKS:

 

Retained Accounts Past QTR = CALCULATE(
                        DISTINCTCOUNT('Sales Result'[Account]),
                        FILTER('Sales Result',[Accounts Ordered Past QTR] > 0 || [Accounts Ordered 2 QTRs Ago] > 0))

 

kotarosai_0-1616430649145.png

 

DOES NOT WORK:

 

Retained Accounts Past QTR = CALCULATE(
                        DISTINCTCOUNT('Sales Result'[Account]),
                        FILTER('Sales Result',[Accounts Ordered Past QTR] > 0 && [Accounts Ordered 2 QTRs Ago] > 0))

 

kotarosai_1-1616430768750.png

 

Accounts Ordered Past QTR = CALCULATE(
                        DISTINCTCOUNT('Sales Result'[Account]),
                        FILTER('Sales Result','Sales Result'[Sales Past QTR] > 0))
Accounts Ordered 2 QTRs Ago = CALCULATE(
                        DISTINCTCOUNT('Sales Result'[Account]),
                        FILTER('Sales Result','Sales Result'[Sales 2 QTRs Ago] > 0))
Sales Past QTR = 
VAR CurrentDate = [Latest Date Loaded]
RETURN
CALCULATE(
    SUM('Sales Result'[Net_Sales_Units__c]),
    FILTER(
        ALL('Date Table'),
            AND('Date Table'[Date]>=IF(MONTH(CurrentDate)<13,Date(Year(CurrentDate),(INT((Month(CurrentDate)-1)/3)-1)*3+1,1),
                                                Date(1900,1,1)
                                    ),
                'Date Table'[Date]<IF(MONTH(CurrentDate)<13,Date(Year(CurrentDate),(INT((Month(CurrentDate)-1)/3)+0)*3+1,1),
                                            Date(1900,1,1)
                                    )
             )
        )
)
Sales 2 QTRs Ago = 
VAR CurrentDate = [Latest Date Loaded]
RETURN
CALCULATE(
    SUM('Sales Result'[Net_Sales_Units__c]),
    FILTER(
        ALL('Date Table'),
            AND('Date Table'[Date]>=IF(MONTH(CurrentDate)<13,Date(Year(CurrentDate),(INT((Month(CurrentDate)-1)/3)-2)*3+1,1),
                                                Date(1900,1,1)
                                    ),
                'Date Table'[Date]<IF(MONTH(CurrentDate)<13,Date(Year(CurrentDate),(INT((Month(CurrentDate)-1)/3)-1)*3+1,1),
                                            Date(1900,1,1)
                                    )
             )
        )
)

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@kotarosai , Try like and check

 

Retained Accounts Past QTR = Countrows(
filter(values('Sales Result'[Account]),'Sales Result',[Accounts Ordered Past QTR] > 0 && [Accounts Ordered 2 QTRs Ago] > 0))

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

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@kotarosai , Try like and check

 

Retained Accounts Past QTR = Countrows(
filter(values('Sales Result'[Account]),'Sales Result',[Accounts Ordered Past QTR] > 0 && [Accounts Ordered 2 QTRs Ago] > 0))

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

That worked great, thanks so much @amitchandak!

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.