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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Singularity9
Helper I
Helper I

Need a measure to count total customers/sales while making a slicer count as AND, not OR.

I have 3 tables.

  • Sales is a list of sales, including a unique Sale ID.
  • Customers is a list of customers for each sale, linked to Sales via Sale ID in a both ways many to one relationship (a single sale can have multiple customers).
  • Conditions is a table of conditions for each sale, also linked to Sales via Sale ID in a both ways many to one relationship (a single sale can have multiple conditions).

 

I would like to create two measures: one to track the total number of sales, and one to track the total number of customers. This part is easy. However, I would like to include the Conditions table as a slicer for this data. I want this slicer to work on AND logic, rather than OR logic.  If I click conditions A and B on the slicer, I want my measures to count the total number of sales/customers which are classed as condition A and B, not A or B.

I have not succeeded at this. I tried installing the custom visual Smart Filter Pro, but for some idiotic reason Power BI doesn't even show the icon for it. I tried several online solutions, like POWER BI SLICER WITH "AND CONDITION" TO FILTER STACKED BAR CHART FOR MULTIPLE ITEMS - Ruki's Blog (r... (didn't work, just gave me the OR totals as normal), Slicer with AND condition in Power BI - RADACAD (didn't work, told me it couldn't find the Conditions table or there wasn't a relationship detected, absolutely wrong but whatever), and Solved: Filtering a Multi-Select Slicer via AND instead of... - Microsoft Fabric Community (didn't work, when I tried to apply two slicers I got "An unexpected error occurred (file mdformula.h, line 615, function 'ValueTypeFromXLSubType')."). So now I come to you. Would you be able to help?

1 ACCEPTED SOLUTION
Singularity9
Helper I
Helper I

Managed it! Using a base from a place I can't find anymore, I created a new unlinked table of distinct conditions, then used the formula below.

Sales with Condition AND = 
IF (
    ISFILTERED ( 'Conditions List'[Condition] )
        && MAX ( 'Conditions'[Condition] )
            IN ALLSELECTED ( 'Conditions List'[Condition] )
                && COUNTROWS ( 'Conditions List' )
                    <= CALCULATE (
                        COUNT ('Conditions'[Sale ID]),                  FILTER (
                            ALLSELECTED ( 'Conditions' ),
                            [Condition]
                                IN ALLSELECTED ( 'Conditions List'[Condition] )
                                    && [Sale ID] = MAX ( 'Conditions List'[Sale ID] )
                        )
                    ),
    1
)

 

I can use this measure as a filter to display a list of sales ids (just set it to "is 1"), or I can create a new calculate distinctcount measure with this measure as a filter.

Total Sales = IF(ISFILTERED('Conditions List')=FALSE(), DISTINCTCOUNT(Sales[Sale ID]),CALCULATE(DISTINCTCOUNT('Conditions'[Sale ID]), FILTER('Conditions', [Sales with Condition AND ]=1)))

 

View solution in original post

1 REPLY 1
Singularity9
Helper I
Helper I

Managed it! Using a base from a place I can't find anymore, I created a new unlinked table of distinct conditions, then used the formula below.

Sales with Condition AND = 
IF (
    ISFILTERED ( 'Conditions List'[Condition] )
        && MAX ( 'Conditions'[Condition] )
            IN ALLSELECTED ( 'Conditions List'[Condition] )
                && COUNTROWS ( 'Conditions List' )
                    <= CALCULATE (
                        COUNT ('Conditions'[Sale ID]),                  FILTER (
                            ALLSELECTED ( 'Conditions' ),
                            [Condition]
                                IN ALLSELECTED ( 'Conditions List'[Condition] )
                                    && [Sale ID] = MAX ( 'Conditions List'[Sale ID] )
                        )
                    ),
    1
)

 

I can use this measure as a filter to display a list of sales ids (just set it to "is 1"), or I can create a new calculate distinctcount measure with this measure as a filter.

Total Sales = IF(ISFILTERED('Conditions List')=FALSE(), DISTINCTCOUNT(Sales[Sale ID]),CALCULATE(DISTINCTCOUNT('Conditions'[Sale ID]), FILTER('Conditions', [Sales with Condition AND ]=1)))

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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