<?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 Performance of SWITCH() in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-of-SWITCH/m-p/3164060#M113720</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;I'm trying to understand, how the first argument of the SWITCH-function is being evaluated/calculated when checking the second arguments.&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Here an example:&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;SWITCH (&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-60px"&gt;SELECTEDVALUE( Product[Color] ) ,&lt;BR /&gt;"Green", 1,&lt;BR /&gt;"Blue", 2,&lt;BR /&gt;"Red", 3&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;)&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Will the SELECTEDVALUE ( Product[Color] ) be calculated at the beginning, then saved like a variable, and then in the second step only compared to the different colors? Or is it computed for every line of comparison new?&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Personally I think that it is beeing calculated once, stored, and then compared. But I was wondering, because I saw someone writing the SWITCH-Function with a variable as TRUE/FALSE argument:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;var color =&amp;nbsp;SELECTEDVALUE( Product[Color] )&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;RETURN&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-60px"&gt;SWITCH (&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-90px"&gt;color ,&lt;BR /&gt;"Green", 1,&lt;BR /&gt;"Blue", 2,&lt;BR /&gt;"Red", 3&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-60px"&gt;)&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-60px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;And this got me thinking, maybe I was wrong. Would be great if someone could enlighten me &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;PS: I'm just curious if there is a difference in performance, that there could be differences when the function is being evaluated row by row I'm aware &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Regards,&lt;/P&gt;&lt;P class="lia-align-left"&gt;Max&lt;/P&gt;</description>
    <pubDate>Thu, 30 Mar 2023 17:47:27 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-03-30T17:47:27Z</dc:date>
    <item>
      <title>Performance of SWITCH()</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-of-SWITCH/m-p/3164060#M113720</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;I'm trying to understand, how the first argument of the SWITCH-function is being evaluated/calculated when checking the second arguments.&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Here an example:&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;SWITCH (&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-60px"&gt;SELECTEDVALUE( Product[Color] ) ,&lt;BR /&gt;"Green", 1,&lt;BR /&gt;"Blue", 2,&lt;BR /&gt;"Red", 3&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;)&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Will the SELECTEDVALUE ( Product[Color] ) be calculated at the beginning, then saved like a variable, and then in the second step only compared to the different colors? Or is it computed for every line of comparison new?&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Personally I think that it is beeing calculated once, stored, and then compared. But I was wondering, because I saw someone writing the SWITCH-Function with a variable as TRUE/FALSE argument:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;var color =&amp;nbsp;SELECTEDVALUE( Product[Color] )&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;RETURN&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-60px"&gt;SWITCH (&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-90px"&gt;color ,&lt;BR /&gt;"Green", 1,&lt;BR /&gt;"Blue", 2,&lt;BR /&gt;"Red", 3&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-60px"&gt;)&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-60px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;And this got me thinking, maybe I was wrong. Would be great if someone could enlighten me &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;PS: I'm just curious if there is a difference in performance, that there could be differences when the function is being evaluated row by row I'm aware &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Regards,&lt;/P&gt;&lt;P class="lia-align-left"&gt;Max&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 17:47:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-of-SWITCH/m-p/3164060#M113720</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-30T17:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Performance of SWITCH()</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-of-SWITCH/m-p/3164571#M113760</link>
      <description>&lt;P&gt;hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SWITCH is runned as nested IFs. So the performance shall be better to save the first argument as a variable. As a variable is calculated once, while without varible, it is calculated in every nested IF, three times in your case.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 01:35:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-of-SWITCH/m-p/3164571#M113760</guid>
      <dc:creator>FreemanZ</dc:creator>
      <dc:date>2023-03-31T01:35:13Z</dc:date>
    </item>
  </channel>
</rss>

