Forum Discussion
Filter Calculate Based on Slicer Selected
- 1 year ago
Hi tomperro
The reason your measure isn’t behaving correctly is because SELECTEDVALUE() only works when one value is selected. If multiple values (or none) are selected, it returns blank and your CALCULATE doesn’t apply the filters as expected.
Here’s a measure that dynamically applies the filters only for slicers with selections:
Dynamic Item Count = CALCULATE ( COUNT ( Item[ItemId] ), // Apply Zone filter only if any selection is made IF ( ISFILTERED ( Location[Zone] ), KEEPFILTERS ( VALUES ( Location[Zone] ) ) ), // Apply Department filter if selected IF ( ISFILTERED ( Location[Department] ), KEEPFILTERS ( VALUES ( Location[Department] ) ) ), // Apply Division filter if selected IF ( ISFILTERED ( Location[Division] ), KEEPFILTERS ( VALUES ( Location[Division] ) ) ) )This will count the items based on any combination of selected slicers. If a slicer isn’t used, it’s ignored exactly what you're after.
Hi tomperro
The reason your measure isn’t behaving correctly is because SELECTEDVALUE() only works when one value is selected. If multiple values (or none) are selected, it returns blank and your CALCULATE doesn’t apply the filters as expected.
Here’s a measure that dynamically applies the filters only for slicers with selections:
Dynamic Item Count =
CALCULATE (
COUNT ( Item[ItemId] ),
// Apply Zone filter only if any selection is made
IF (
ISFILTERED ( Location[Zone] ),
KEEPFILTERS ( VALUES ( Location[Zone] ) )
),
// Apply Department filter if selected
IF (
ISFILTERED ( Location[Department] ),
KEEPFILTERS ( VALUES ( Location[Department] ) )
),
// Apply Division filter if selected
IF (
ISFILTERED ( Location[Division] ),
KEEPFILTERS ( VALUES ( Location[Division] ) )
)
)
This will count the items based on any combination of selected slicers. If a slicer isn’t used, it’s ignored exactly what you're after.