Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have 3 tables.
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?
Solved! Go to Solution.
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)))
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)))
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
12 | |
10 | |
6 |