<?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: Switch in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2466612#M67021</link>
    <description>&lt;P&gt;ok thx .&amp;nbsp;&lt;/P&gt;&lt;P&gt;i just generate all&amp;nbsp; dynamic measures by python without any IF or switch and deploy every night over XMLA .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Apr 2022 13:15:15 GMT</pubDate>
    <dc:creator>dim123dim123</dc:creator>
    <dc:date>2022-04-20T13:15:15Z</dc:date>
    <item>
      <title>Switch</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2465650#M67001</link>
      <description>&lt;P&gt;Hi i have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;vAR s=max( 'Account Schedule'[ScheduleName] )&lt;BR /&gt;VAR s1=SWITCH(&lt;BR /&gt;TRUE( ),&lt;BR /&gt;--s = "ARU1", [Balance_1],&lt;BR /&gt;--s = "ARU2", [Balance_2],&lt;BR /&gt;--s = "ARU3", [Balance_3],&lt;BR /&gt;--s = "ARU4", [Balance_4],&lt;BR /&gt;--s = "ARU5", [Balance_5],&lt;BR /&gt;s = "ARU6", [Balance_6],&lt;BR /&gt;CALCULATE( [GL Net Change], FILTER( ALL( 'dim Date' ), 'dim Date'[Date] &amp;lt;= MAX( 'dim Date'[Date] ) ) )&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;)&lt;BR /&gt;RETURN s1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This switch choose Measure that depends what kind of report Type are selected .&lt;BR /&gt;Why when i uncomment all lines , process time is&amp;nbsp; about 2 minutes ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i optimize/solve this ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 10:41:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2465650#M67001</guid>
      <dc:creator>dim123dim123</dc:creator>
      <dc:date>2022-04-20T10:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: Switch</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2465961#M67005</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="380733" data-lia-user-login="dim123dim123" class="lia-mention lia-mention-user"&gt;dim123dim123&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please share the code of the 6 measures?&lt;/P&gt;&lt;P&gt;also please advise how your report look like&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 11:22:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2465961#M67005</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-04-20T11:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Switch</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2465999#M67007</link>
      <description>&lt;P&gt;Code is huge and allmost same for 6 measures.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;like&amp;nbsp;&lt;/P&gt;&lt;P&gt;VAR GL_tmp_7 =&lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM( 'fact Transaction'[amount] ),&lt;BR /&gt;FILTER( ALLEXCEPT( 'Account Schedule', 'Account Schedule'[ScheduleName] ), 'Account Schedule'[LineNo] IN { 7 } ),&lt;BR /&gt;FILTER( ALL( 'dim Date' ), 'dim Date'[Date] &amp;lt;= MAX( 'dim Date'[Date] ) )&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&lt;/P&gt;&lt;P&gt;VAR GL_Net_Change_New =&lt;BR /&gt;SWITCH(&lt;BR /&gt;TRUE( ),&lt;BR /&gt;max( 'Account Schedule'[LineNo] ) = 7, GL_tmp_7,&lt;BR /&gt;max( 'Account Schedule'[LineNo] ) = 333, GL_tmp_333&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;return&amp;nbsp;GL_Net_Change_New&lt;/P&gt;&lt;P&gt;But my question is why switch calculate code for all conditions ? or why so slow ? each switch line work correctrly and fast.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried : IF ( &lt;SPAN&gt;s = "ARU6", [Balance_6], if (s = "ARU5", [Balance_5],&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;same result slow . seems engie&amp;nbsp; calculate&amp;nbsp; each line conditions&amp;nbsp;measure &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/SPAN&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;</description>
      <pubDate>Wed, 20 Apr 2022 11:33:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2465999#M67007</guid>
      <dc:creator>dim123dim123</dc:creator>
      <dc:date>2022-04-20T11:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Switch</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2466274#M67008</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="380733" data-lia-user-login="dim123dim123" class="lia-mention lia-mention-user"&gt;dim123dim123&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It does not but your calcutions are too heavy. Many things can be improved. For example as long as the 6 measures have very similar structure then I would advide to have their codes directly implemented inside the final measure. This way you can avoid multiple scans of the same table and duplicated calculations. I can give more details on how to do that.&amp;nbsp;&lt;BR /&gt;the other important thing is filter ALL Date Table. Why do you need to filter it all?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 11:58:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2466274#M67008</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-04-20T11:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Switch</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2466479#M67015</link>
      <description>&lt;P&gt;sorry 6 measures have similar structure code but not same .&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need calculate dynamic account sheduler report based on user defined totaling rules&amp;nbsp;&lt;/P&gt;&lt;P&gt;but why this code is&amp;nbsp; fast&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;VAR s=max( 'Account Schedule'[ScheduleName] )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;return if ( s = "ARU1", [Balance_1],&amp;nbsp;CALCULATE( [GL Net Change], FILTER( ALL( 'dim Date' ), 'dim Date'[Date] &amp;lt;= MAX( 'dim Date'[Date] ) ) )&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and similar almost 2 times slower&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;VAR s=max( 'Account Schedule'[ScheduleName] )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;return if ( s = "ARU1", [Balance_1],&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if (&amp;nbsp; s = "ARU2", [Balance_2],&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;CALCULATE( [GL Net Change], FILTER( ALL( 'dim Date' ), 'dim Date'[Date] &amp;lt;= MAX( 'dim Date'[Date] ) ) )&lt;/SPAN&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;&lt;P&gt;how can i create somthing like this :&amp;nbsp;&lt;/P&gt;&lt;P&gt;VAR s = MAX( 'Account Schedule'[ScheduleName] )&lt;BR /&gt;return&amp;nbsp; IF(s == "ARU1", [Balance_1])&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;return&amp;nbsp; IF(s == "ARU2", [Balance_2])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or something like this ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 12:26:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2466479#M67015</guid>
      <dc:creator>dim123dim123</dc:creator>
      <dc:date>2022-04-20T12:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Switch</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2466578#M67019</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="380733" data-lia-user-login="dim123dim123" class="lia-mention lia-mention-user"&gt;dim123dim123&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The conditions need to be checked one by one. Checking requires the evalution of the condition calculation. The evaluation continues one by one until the first codition is satisfied. Only then, the rest of the conditions will be igoned.&amp;nbsp;&lt;BR /&gt;Your cide requires optimization. And of tge steps is refrain from reffering to measures and rewrite the measure completely from scratch. This will be painful but afterall is necessary to have a healty report. when doing that, vertual tables will be created only once and then stored in a variable to be used over annd over again to evalute all the conditions.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 13:03:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2466578#M67019</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-04-20T13:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Switch</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2466612#M67021</link>
      <description>&lt;P&gt;ok thx .&amp;nbsp;&lt;/P&gt;&lt;P&gt;i just generate all&amp;nbsp; dynamic measures by python without any IF or switch and deploy every night over XMLA .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 13:15:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Switch/m-p/2466612#M67021</guid>
      <dc:creator>dim123dim123</dc:creator>
      <dc:date>2022-04-20T13:15:15Z</dc:date>
    </item>
  </channel>
</rss>

