Forum Discussion
Filtering only when value is selected in slicer
- 3 years ago
Hello CMunteanu
You could use a function like HASONEFILTER to check whether there is a single value filtered on a the slicer columns.
The "negation" of the HASONEFILTER check could then be OR-ed with each of the existing boolean conditions used within CALCULATETABLE for _table1.
Using variables to store these additional checks, the result would be something like this:
VAR _SlicerProduct_SingleFilter = HASONEFILTER ( 'Slicer'[PRODUCT] ) VAR _SlicerStore_SingleFilter = HASONEFILTER ( 'SlicerStore'[STORE_ID] ) VAR _SlicerYear_SingleFilter = HASONEFILTER ( 'SlicerYear'[YEAR_ID] ) VAR _table1 = CALCULATETABLE ( VALUES ( 'OrdersFact'[CUSTOMER_ID] ), 'OrdersFact'[PRODUCT_ID] = _ProductID || NOT _SlicerProduct_SingleFilter, 'OrdersFact'[Store] = _StoreID || NOT _SlicerStore_SingleFilter, 'OrdersFact'[Year] = _YearID || NOT _SlicerYear_SingleFilter )I think this would be the safest way to write it. You could also write the conditions like this, assuming there are always at least two values available on the slicers:
'OrdersFact'[PRODUCT_ID] = _ProductID || ISBLANK ( _ProductID )Does the above code work for you?
Hello CMunteanu
You could use a function like HASONEFILTER to check whether there is a single value filtered on a the slicer columns.
The "negation" of the HASONEFILTER check could then be OR-ed with each of the existing boolean conditions used within CALCULATETABLE for _table1.
Using variables to store these additional checks, the result would be something like this:
VAR _SlicerProduct_SingleFilter =
HASONEFILTER ( 'Slicer'[PRODUCT] )
VAR _SlicerStore_SingleFilter =
HASONEFILTER ( 'SlicerStore'[STORE_ID] )
VAR _SlicerYear_SingleFilter =
HASONEFILTER ( 'SlicerYear'[YEAR_ID] )
VAR _table1 =
CALCULATETABLE (
VALUES ( 'OrdersFact'[CUSTOMER_ID] ),
'OrdersFact'[PRODUCT_ID] = _ProductID || NOT _SlicerProduct_SingleFilter,
'OrdersFact'[Store] = _StoreID || NOT _SlicerStore_SingleFilter,
'OrdersFact'[Year] = _YearID || NOT _SlicerYear_SingleFilter
)
I think this would be the safest way to write it. You could also write the conditions like this, assuming there are always at least two values available on the slicers:
'OrdersFact'[PRODUCT_ID] = _ProductID || ISBLANK ( _ProductID )
Does the above code work for you?
Hi Owen,
Many thanks for your answer, it works perfectly fine.
Regards