<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Filtering only when value is selected in slicer in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-only-when-value-is-selected-in-slicer/m-p/3228327#M118334</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code that is part of a bigger measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Measure ORDER2 =
Var _Product=SELECTEDVALUE('Slicer'[PRODUCT])
Var _Store=SELECTEDVALUE('SlicerStore'[STORE_ID])
Var _Year=SELECTEDVALUE('SlicerYear'[YEAR_ID])
Var _ProductID=CALCULATETABLE(VALUES('ProductDim'[PRODUCT_ID]),'ProductDim'[PRODUCT]=_Product)
Var _StoreID=CALCULATETABLE(VALUES('StoreDim'[STORE_ID]),'StoreDim'[STORE_ID]=_Store)
Var _YearID=CALCULATETABLE(VALUES('YearDim'[YEAR_ID]),'YearDim'[YEAR_ID]=_Year)
Var _table1=CALCULATETABLE(VALUES('OrdersFact'[CUSTOMER_ID]),'OrdersFact'[PRODUCT_ID]=_ProductID, OrdersFact[Store]=_StoreID, 'OrdersFact'[Year]=_YearID)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;We have 3 slicers one for Product, Store, Year which correspond to three dimensions related to the Orders Fact. We want to change _table1 variable so that when we don't select a value in the slicer (or select all values), the filter in the CALCULATETABLE expression will not filter rows, that is to say: the filter should apply only when we have a selected value in the corresponding slicer.&amp;nbsp; What would be the best and most scalable solution that would work for 3 or more filters, taking into account that we may have all combinations of slicers selections (some have a value selected, some not).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 May 2023 09:57:10 GMT</pubDate>
    <dc:creator>CMunteanu</dc:creator>
    <dc:date>2023-05-10T09:57:10Z</dc:date>
    <item>
      <title>Filtering only when value is selected in slicer</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-only-when-value-is-selected-in-slicer/m-p/3228327#M118334</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code that is part of a bigger measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Measure ORDER2 =
Var _Product=SELECTEDVALUE('Slicer'[PRODUCT])
Var _Store=SELECTEDVALUE('SlicerStore'[STORE_ID])
Var _Year=SELECTEDVALUE('SlicerYear'[YEAR_ID])
Var _ProductID=CALCULATETABLE(VALUES('ProductDim'[PRODUCT_ID]),'ProductDim'[PRODUCT]=_Product)
Var _StoreID=CALCULATETABLE(VALUES('StoreDim'[STORE_ID]),'StoreDim'[STORE_ID]=_Store)
Var _YearID=CALCULATETABLE(VALUES('YearDim'[YEAR_ID]),'YearDim'[YEAR_ID]=_Year)
Var _table1=CALCULATETABLE(VALUES('OrdersFact'[CUSTOMER_ID]),'OrdersFact'[PRODUCT_ID]=_ProductID, OrdersFact[Store]=_StoreID, 'OrdersFact'[Year]=_YearID)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;We have 3 slicers one for Product, Store, Year which correspond to three dimensions related to the Orders Fact. We want to change _table1 variable so that when we don't select a value in the slicer (or select all values), the filter in the CALCULATETABLE expression will not filter rows, that is to say: the filter should apply only when we have a selected value in the corresponding slicer.&amp;nbsp; What would be the best and most scalable solution that would work for 3 or more filters, taking into account that we may have all combinations of slicers selections (some have a value selected, some not).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 09:57:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-only-when-value-is-selected-in-slicer/m-p/3228327#M118334</guid>
      <dc:creator>CMunteanu</dc:creator>
      <dc:date>2023-05-10T09:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering only when value is selected in slicer</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-only-when-value-is-selected-in-slicer/m-p/3228628#M118376</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="498599" data-lia-user-login="CMunteanu" class="lia-mention lia-mention-user"&gt;CMunteanu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use a function like HASONEFILTER to check whether there is a single value filtered on a the slicer columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "negation" of the HASONEFILTER check could then be OR-ed with each of the existing boolean conditions used within CALCULATETABLE for _table1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using variables to store these additional checks, the result would be something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;'OrdersFact'[PRODUCT_ID] = _ProductID || ISBLANK ( _ProductID )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the above code work for you?&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 11:08:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-only-when-value-is-selected-in-slicer/m-p/3228628#M118376</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-05-10T11:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering only when value is selected in slicer</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-only-when-value-is-selected-in-slicer/m-p/3228803#M118391</link>
      <description>&lt;P&gt;Hi Owen,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your answer, it works perfectly fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 12:57:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-only-when-value-is-selected-in-slicer/m-p/3228803#M118391</guid>
      <dc:creator>CMunteanu</dc:creator>
      <dc:date>2023-05-10T12:57:20Z</dc:date>
    </item>
  </channel>
</rss>

