<?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: Performance Issue due to Switch Function in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-due-to-Switch-Function/m-p/2996042#M100963</link>
    <description>&lt;P&gt;That measure doesn't look that bad, and the suggested improvements should only help. How many rows in your fact table? More importantly, how many distinct values do you have in the Value_Col column? Is it whole number? or decimal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pat&lt;/P&gt;</description>
    <pubDate>Sun, 01 Jan 2023 19:22:52 GMT</pubDate>
    <dc:creator>ppm1</dc:creator>
    <dc:date>2023-01-01T19:22:52Z</dc:date>
    <item>
      <title>Performance Issue due to Switch Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-due-to-Switch-Function/m-p/2995308#M100916</link>
      <description>&lt;P&gt;I am having serious performance issue due to this measure. Anyone could help please to have an alternative that might not make the report slow? Just to let you know I am new to dax.&amp;nbsp;thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;EM&gt;Measure_NightMare &amp;nbsp;= &lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;VAR caldate =&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; SELECTEDVALUE ( 'Calendar'[DayOfWeek] )&amp;nbsp;&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;RETURN&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; SWITCH (&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TRUE (),&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; caldate = 6,&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CALCULATE (&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SUMX ( 'Fact_TBL', 'Fact_TBL'[Col1] )&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - SUMX ( 'Fact_TBL', 'Fact_TBL'[Col2] ),&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'Fact_TBL'[Value_Col] &amp;gt;= 40&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;&amp;amp; 'Fact_TBL'[Value_Col] &amp;lt;= 74&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; caldate = 7,&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BLANK ()&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , &lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CALCULATE (&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SUMX ( 'Fact_TBL', 'Fact_TBL'[Col1] )&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - SUMX ( 'Fact_TBL', 'Fact_TBL'[Col2] ),&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'Fact_TBL'[Value_Col] &amp;gt;= 38&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;&amp;amp; 'Fact_TBL'[Value_Col] &amp;lt;= 80&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; )&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 30 Dec 2022 21:12:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-due-to-Switch-Function/m-p/2995308#M100916</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-12-30T21:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue due to Switch Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-due-to-Switch-Function/m-p/2995327#M100918</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;You might try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure_NightMare  =
VAR caldate = SELECTEDVALUE ( 'Calendar'[DayOfWeek] )
RETURN
    SWITCH (
        TRUE(),
        caldate&amp;lt;6,
               VAR __Table = FILTER(ALLSELECTED('Fact_TBL'),[Value_Col] &amp;gt;= 40 &amp;amp;&amp;amp; [Value_Col] &amp;lt;= 74)
            RETURN
                SUMX ( __Table, [Col1] ) - SUMX(__Table, [Col2] ),
        caldate = 6,
               VAR __Table = FILTER(ALLSELECTED('Fact_TBL'),[Value_Col] &amp;gt;= 40 &amp;amp;&amp;amp; [Value_Col] &amp;lt;= 74)
            RETURN
                SUMX ( __Table, [Col1] ) - SUMX(__Table, [Col2] ),
            BLANK ()
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2022 22:10:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-due-to-Switch-Function/m-p/2995327#M100918</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2022-12-30T22:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue due to Switch Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-due-to-Switch-Function/m-p/2995717#M100942</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;It's not clear to me why this is slow but I've struggled with SWITCH myself. You may want to check out some of the links referenced &lt;A href="https://stackoverflow.com/questions/61805513/force-dax-switch-function-to-use-strict-lazy-short-circuit-evaluation" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's possible rearranging the order of the terms could help if you start with the simplest case. That is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;Measure_NightMare =
VAR caldate =
    SELECTEDVALUE ( 'Calendar'[DayOfWeek] )
RETURN
    SWITCH (
        TRUE (),
        caldate = 7, BLANK (),
        caldate = 6,
            CALCULATE (
                SUMX ( 'Fact_TBL', 'Fact_TBL'[Col1] ) - SUMX ( 'Fact_TBL', 'Fact_TBL'[Col2] ),
                'Fact_TBL'[Value_Col] &amp;gt;= 40
                    &amp;amp;&amp;amp; 'Fact_TBL'[Value_Col] &amp;lt;= 74
            ),
        CALCULATE (
            SUMX ( 'Fact_TBL', 'Fact_TBL'[Col1] ) - SUMX ( 'Fact_TBL', 'Fact_TBL'[Col2] ),
            'Fact_TBL'[Value_Col] &amp;gt;= 38
                &amp;amp;&amp;amp; 'Fact_TBL'[Value_Col] &amp;lt;= 80
        )
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also try refactoring it using variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;NightMare = 
VAR caldate =
    SELECTEDVALUE ( 'Calendar'[DayOfWeek] )
VAR case6 =
    CALCULATE (
        SUM ( 'Fact_TBL'[Col1] ) - SUM ( 'Fact_TBL'[Col2] ),
        'Fact_TBL'[Value_Col] &amp;gt;= 40,
        'Fact_TBL'[Value_Col] &amp;lt;= 74
    )
VAR other =
    CALCULATE (
        SUM ( 'Fact_TBL'[Col1] ) - SUM ( 'Fact_TBL'[Col2] ),
        'Fact_TBL'[Value_Col] &amp;gt;= 38,
        'Fact_TBL'[Value_Col] &amp;lt;= 80
    )
RETURN
    SWITCH (
        caldate,
        7, BLANK (),
        6, case6,
        other
    )
&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 31 Dec 2022 20:45:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-due-to-Switch-Function/m-p/2995717#M100942</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2022-12-31T20:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue due to Switch Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-due-to-Switch-Function/m-p/2996042#M100963</link>
      <description>&lt;P&gt;That measure doesn't look that bad, and the suggested improvements should only help. How many rows in your fact table? More importantly, how many distinct values do you have in the Value_Col column? Is it whole number? or decimal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pat&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2023 19:22:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-due-to-Switch-Function/m-p/2996042#M100963</guid>
      <dc:creator>ppm1</dc:creator>
      <dc:date>2023-01-01T19:22:52Z</dc:date>
    </item>
  </channel>
</rss>

