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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Marc_Ponick
Regular Visitor

Dax expression that can be filtered by a slicer that only affects one measure

Looking to see if a Dax measure can be written so that the values displayed in a matrix will only be affected by specific slicers for each measure.

Matrix would look like:

Sales Agent  | Apples Orders Placed Count | Sold Apples Order Count

Dave Smith  | 200                                         | 150

 

DAX:

Apple Orders Placed Count = Calculate(DISTINCTCOUNT('Inventory Data'[Order ID]), 'Inventory Data'[Fruit] = "Apples",'Inventory Data'[Placed] = "True")
Sold Apple Orders Count = Calculate(DISTINCTCOUNT('Inventory Data'[Order ID]), 'Inventory Data'[Fruit] = "Apples",'Inventory Data'[Sold] = "True")
 
The received apples will have it's own year slicer, and the sold apples will have it's own as well. You could choose Placed year = 2022, Sold year = 2022, or 2023.  Placed year cannot infuence sold year and vice versa.
 
Example of how it would be written (but doesn't work):
Apple Orders Placed Count = Calculate(DISTINCTCOUNT('Inventory Data'[Order ID]), 'Inventory Data'[Fruit] = "Apples",'Inventory Data'[Placed] = "True" AllSELECTED('Inventory Data'[Placed Year]))
 
Sold Apple Orders Count = Calculate(DISTINCTCOUNT('Inventory Data'[Order ID]), 'Inventory Data'[Fruit] = "Apples",'Inventory Data'[Sold] = "True",AllSELECTED('Inventory Data'[Sold Year]))
 
'Inventory Data'[Placed Year] and 'Inventory Data'[Sold Year] would be individual slicers on the report page but would only apply to the related DAX measures in the Matrix
There are a number of fruit options in the Matrix values, each with it's own measures, all following the same logic as Apples.
1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @Marc_Ponick ,

Please have a try.

Apple Orders Placed Count - This measure will only be influenced by the 'Placed Year' slicer:

Apple Orders Placed Count =
CALCULATE(
DISTINCTCOUNT('Inventory Data'[Order ID]),
'Inventory Data'[Fruit] = "Apples",
'Inventory Data'[Placed] = "True",
ALLEXCEPT('Inventory Data', 'Inventory Data'[Placed Year])
)


Sold Apple Orders Count- This measure will only be influenced by the 'Sold Year' slicer:

Sold Apple Orders Count =
CALCULATE(
DISTINCTCOUNT('Inventory Data'[Order ID]),
'Inventory Data'[Fruit] = "Apples",
'Inventory Data'[Sold] = "True",
ALLEXCEPT('Inventory Data', 'Inventory Data'[Sold Year])
)


The ALLEXCEPT function keeps the filters for the specified columns and removes all other context filters from the table. This way, each measure will only respond to its respective slicer.

ALLEXCEPT function (DAX) - DAX | Microsoft Learn

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

1 REPLY 1
v-rongtiep-msft
Community Support
Community Support

Hi @Marc_Ponick ,

Please have a try.

Apple Orders Placed Count - This measure will only be influenced by the 'Placed Year' slicer:

Apple Orders Placed Count =
CALCULATE(
DISTINCTCOUNT('Inventory Data'[Order ID]),
'Inventory Data'[Fruit] = "Apples",
'Inventory Data'[Placed] = "True",
ALLEXCEPT('Inventory Data', 'Inventory Data'[Placed Year])
)


Sold Apple Orders Count- This measure will only be influenced by the 'Sold Year' slicer:

Sold Apple Orders Count =
CALCULATE(
DISTINCTCOUNT('Inventory Data'[Order ID]),
'Inventory Data'[Fruit] = "Apples",
'Inventory Data'[Sold] = "True",
ALLEXCEPT('Inventory Data', 'Inventory Data'[Sold Year])
)


The ALLEXCEPT function keeps the filters for the specified columns and removes all other context filters from the table. This way, each measure will only respond to its respective slicer.

ALLEXCEPT function (DAX) - DAX | Microsoft Learn

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

 

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors