<?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 Re: calculatetable with conditional filter in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculatetable-with-conditional-filter/m-p/4594739#M175945</link>
    <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="700437" data-lia-user-login="OffermansWE" class="lia-mention lia-mention-user"&gt;OffermansWE&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;you can use this formula to create table&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;VAR _table = 
    CALCULATETABLE('Unpivoted waarden',
                   'Unpivoted waarden'[Column_name] = _column_name
            IF(NOT(ISBLANK(_onderscheid)), 
            'Unpivoted waarden'[BB/NB] = _onderscheid || 
            'Unpivoted waarden'[W/U] = _onderscheid || 
            'Unpivoted waarden'[Gebruik_woon] = _onderscheid))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then count the row&lt;BR /&gt;VAR _count = COUNTROWS(_table)&lt;BR /&gt;RETURN&lt;BR /&gt;_count&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;SPAN&gt;, then please give us Kudos and consider&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;Accept it as a solution&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Mar 2025 10:25:18 GMT</pubDate>
    <dc:creator>vivek31</dc:creator>
    <dc:date>2025-03-04T10:25:18Z</dc:date>
    <item>
      <title>calculatetable with conditional filter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculatetable-with-conditional-filter/m-p/4594697#M175944</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to count the rows of a table filtered by two conditions. For this condition A always needs to be true. The second filter is conditional: if _onderscheid is not blank, the table column[onderscheid] should be equal to onderscheid, if the filter is blank, the additional filter is not required. The _onderscheid variable is a text value, or can be blank. The _onderscheid can be found in three columns in the table to be filtered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created the VAR _table where I calculate a table like:&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;_table&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;calculatetable&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;'Unpivoted waarden'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-60px"&gt;&lt;SPAN&gt;'Unpivoted waarden'&lt;/SPAN&gt;&lt;SPAN&gt;[Column_name]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;_column_name&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-60px"&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Unpivoted waarden'&lt;/SPAN&gt;&lt;SPAN&gt;[BB/NB]&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt; {(&lt;/SPAN&gt;&lt;SPAN&gt;_onderscheid&lt;/SPAN&gt;&lt;SPAN&gt;)} || &lt;/SPAN&gt;&lt;SPAN&gt;'Unpivoted waarden'&lt;/SPAN&gt;&lt;SPAN&gt;[W/U]&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt; {(&lt;/SPAN&gt;&lt;SPAN&gt;_onderscheid&lt;/SPAN&gt;&lt;SPAN&gt;)} || &lt;/SPAN&gt;&lt;SPAN&gt;'Unpivoted waarden'&lt;/SPAN&gt;&lt;SPAN&gt;[Gebruik_woon]&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt; {(&lt;/SPAN&gt;&lt;SPAN&gt;_onderscheid&lt;/SPAN&gt;&lt;SPAN&gt;)}) &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;In this case, if I return countrows(_table) does return nothing for the values where _onderscheid is blank. How can I make sure that the second filter of the calculatetable function is not used when the _onderscheid value is blank?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I eventually need to perform a switch function on the countrows for an additional filter. Therefore, I cannot put the countrows(calculatetable()) in an if() function. So it would be best if the problem could be solved within assigning the _table variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 04 Mar 2025 09:53:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculatetable-with-conditional-filter/m-p/4594697#M175944</guid>
      <dc:creator>OffermansWE</dc:creator>
      <dc:date>2025-03-04T09:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: calculatetable with conditional filter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculatetable-with-conditional-filter/m-p/4594739#M175945</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="700437" data-lia-user-login="OffermansWE" class="lia-mention lia-mention-user"&gt;OffermansWE&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;you can use this formula to create table&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;VAR _table = 
    CALCULATETABLE('Unpivoted waarden',
                   'Unpivoted waarden'[Column_name] = _column_name
            IF(NOT(ISBLANK(_onderscheid)), 
            'Unpivoted waarden'[BB/NB] = _onderscheid || 
            'Unpivoted waarden'[W/U] = _onderscheid || 
            'Unpivoted waarden'[Gebruik_woon] = _onderscheid))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then count the row&lt;BR /&gt;VAR _count = COUNTROWS(_table)&lt;BR /&gt;RETURN&lt;BR /&gt;_count&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;SPAN&gt;, then please give us Kudos and consider&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;Accept it as a solution&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 10:25:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculatetable-with-conditional-filter/m-p/4594739#M175945</guid>
      <dc:creator>vivek31</dc:creator>
      <dc:date>2025-03-04T10:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: calculatetable with conditional filter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculatetable-with-conditional-filter/m-p/4594771#M175948</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="700437" data-lia-user-login="OffermansWE" class="lia-mention lia-mention-user"&gt;OffermansWE&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You need to modify your CALCULATETABLE function so that the second filter condition is applied only when _onderscheid is not blank. When _onderscheid is blank, it should not filter the table based on BB/NB, W/U, or Gebruik_woon.&lt;/P&gt;
&lt;P&gt;You can achieve this by modifying your VAR _table as follows:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR _table =
CALCULATETABLE(
'Unpivoted waarden',
'Unpivoted waarden'[Column_name] = _column_name,
IF(
ISBLANK(_onderscheid),
TRUE(),
'Unpivoted waarden'[BB/NB] = _onderscheid ||
'Unpivoted waarden'[W/U] = _onderscheid ||
'Unpivoted waarden'[Gebruik_woon] = _onderscheid
)
)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;This way, _table correctly includes all rows when _onderscheid is blank, and only filters based on _onderscheid when it is provided.&lt;/P&gt;
&lt;P&gt;Now, when you use COUNTROWS(_table), it should return the correct count for both blank and non-blank cases of _onderscheid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please mark this post as solution if it helps you. Appreciate Kudos.&lt;/STRONG&gt;&lt;/EM&gt;&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;</description>
      <pubDate>Tue, 04 Mar 2025 10:53:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculatetable-with-conditional-filter/m-p/4594771#M175948</guid>
      <dc:creator>FarhanJeelani</dc:creator>
      <dc:date>2025-03-04T10:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: calculatetable with conditional filter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculatetable-with-conditional-filter/m-p/4594845#M175957</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="692058" data-lia-user-login="vivek31" class="lia-mention lia-mention-user"&gt;vivek31&lt;/a&gt;&amp;nbsp;As a result, i get the values for when _onmogelijk is not blank. However, I do not get any results when _onmogelijk is blank. The cells in the calculated column are blank for the cells where _onmogelijk is blank.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 12:03:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculatetable-with-conditional-filter/m-p/4594845#M175957</guid>
      <dc:creator>OffermansWE</dc:creator>
      <dc:date>2025-03-04T12:03:49Z</dc:date>
    </item>
  </channel>
</rss>

