<?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: DAX VAR Function in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/951462#M10691</link>
    <description>&lt;P&gt;Hi there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to first kindly ask you: Do not create monster formulas. It's not fun, I assure you, especially for those who will have to maintain such code. Also, please format your measures when you post them on the forum. Please respect your readers' time. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I'll tell you why your monster does not work. It's because variables to which you've assigned values are STATIC. They cannot be changed. Here's your measure formatted (&lt;A href="http://www.daxformatter.com" target="_blank"&gt;www.daxformatter.com&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;TEST =
VAR CentreHeadcount =
    CALCULATE (
        COUNT ( 'Centre Employees'[Employee ID] ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
VAR CentreTerminations =
    CALCULATE (
        DISTINCTCOUNT ( 'Centre Terminations'[Employee ID] ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
VAR Terminations12MTD =
    CALCULATE (
        CentreTerminations, -- STATIC VALUE!!!
        DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -12, MONTH ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
VAR Headcount12MTD =
    CALCULATE (
        AVERAGEX ( ALLSELECTED ( 'Calendar' ), CentreHeadcount ), -- = CENTREHEADCOUNT always or BLANK
        DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -12, MONTH ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
RETURN
    CALCULATE (
        IF (
            DIVIDE ( Terminations12MTD, Headcount12MTD ) = BLANK (),
            0,
            DIVIDE ( Terminations12MTD, Headcount12MTD )
        ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
&lt;/LI-CODE&gt;
&lt;P&gt;Also, there's no need to have multiple RETURNs in there. This only obscures the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, ALLSELECTED is a very complex function. The most complex function in whole DAX. Do you fully understand what it does? Do you know what shadow context is? I'll give you a hint that will save your life: Please never use in your code something the functionality of which you don't fully understand. If you do use it, you'll be having countless bugs, many of which you'll not be even aware of.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;D&lt;/P&gt;</description>
    <pubDate>Thu, 27 Feb 2020 18:07:30 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-02-27T18:07:30Z</dc:date>
    <item>
      <title>DAX VAR Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/950213#M10615</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get a VAR formula to work to avoid having multiple measures to calculate Turnover.&lt;BR /&gt;&lt;BR /&gt;Currently I have five measures to calculate Turnover (see below), I am hoping to reduce that to one with VAR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Centre Headcount&lt;/LI&gt;&lt;LI&gt;Centre Headcount 12MTD Average&lt;/LI&gt;&lt;LI&gt;Centre Terminations&lt;/LI&gt;&lt;LI&gt;Centre Terminations 12MTD&lt;/LI&gt;&lt;LI&gt;Centre Turnover&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Invidually they all work however when I put them in one formula I get 0%.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I have done my test Measure:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;TEST = 
VAR CentreHeadcount = CALCULATE(COUNT('Centre Employees'[Employee ID]),'Calendar'[Month Offset]&amp;gt;0)
VAR CentreTerminations = CALCULATE(DISTINCTCOUNT('Centre Terminations'[Employee ID]),'Calendar'[Month Offset]&amp;gt;0)

return

VAR Terminations12MTD = CALCULATE(CentreTerminations,DATESINPERIOD('Calendar'[Date],LASTDATE('Calendar'[Date]),-12, MONTH),'Calendar'[Month Offset]&amp;gt;0)
VAR Headcount12MTD = CALCULATE(AVERAGEX(ALLSELECTED('Calendar'),CentreHeadcount),DATESINPERIOD('Calendar'[Date],LASTDATE('Calendar'[Date]),-12, MONTH),'Calendar'[Month Offset]&amp;gt;0)

return

CALCULATE(IF(DIVIDE(Terminations12MTD,Headcount12MTD)=BLANK(),0,DIVIDE(Terminations12MTD,Headcount12MTD)),'Calendar'[Month Offset]&amp;gt;0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As mentioned each of these steps work on their own however once put into one equation they don't.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 04:14:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/950213#M10615</guid>
      <dc:creator>JP8991</dc:creator>
      <dc:date>2020-02-27T04:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: DAX VAR Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/950283#M10617</link>
      <description>&lt;P&gt;Very difficult to troubleshoot without sample data.&amp;nbsp;Please see this post regarding How to Get Your Question Answered Quickly: &lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That being said, I would change your return to test the various parts of your formula, such as:&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;TEST = 
VAR CentreHeadcount = CALCULATE(COUNT('Centre Employees'[Employee ID]),'Calendar'[Month Offset]&amp;gt;0)
VAR CentreTerminations = CALCULATE(DISTINCTCOUNT('Centre Terminations'[Employee ID]),'Calendar'[Month Offset]&amp;gt;0)

return

VAR Terminations12MTD = CALCULATE(CentreTerminations,DATESINPERIOD('Calendar'[Date],LASTDATE('Calendar'[Date]),-12, MONTH),'Calendar'[Month Offset]&amp;gt;0)
VAR Headcount12MTD = CALCULATE(AVERAGEX(ALLSELECTED('Calendar'),CentreHeadcount),DATESINPERIOD('Calendar'[Date],LASTDATE('Calendar'[Date]),-12, MONTH),'Calendar'[Month Offset]&amp;gt;0)

return
Terminations12MTD
//CALCULATE(IF(DIVIDE(Terminations12MTD,Headcount12MTD)=BLANK(),0,DIVIDE(Terminations12MTD,Headcount12MTD)),'Calendar'[Month Offset]&amp;gt;0)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, see if that value is BLANK and if it is that would explain why you are getting 0% back&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 05:14:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/950283#M10617</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-02-27T05:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: DAX VAR Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/951462#M10691</link>
      <description>&lt;P&gt;Hi there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to first kindly ask you: Do not create monster formulas. It's not fun, I assure you, especially for those who will have to maintain such code. Also, please format your measures when you post them on the forum. Please respect your readers' time. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I'll tell you why your monster does not work. It's because variables to which you've assigned values are STATIC. They cannot be changed. Here's your measure formatted (&lt;A href="http://www.daxformatter.com" target="_blank"&gt;www.daxformatter.com&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;TEST =
VAR CentreHeadcount =
    CALCULATE (
        COUNT ( 'Centre Employees'[Employee ID] ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
VAR CentreTerminations =
    CALCULATE (
        DISTINCTCOUNT ( 'Centre Terminations'[Employee ID] ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
VAR Terminations12MTD =
    CALCULATE (
        CentreTerminations, -- STATIC VALUE!!!
        DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -12, MONTH ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
VAR Headcount12MTD =
    CALCULATE (
        AVERAGEX ( ALLSELECTED ( 'Calendar' ), CentreHeadcount ), -- = CENTREHEADCOUNT always or BLANK
        DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -12, MONTH ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
RETURN
    CALCULATE (
        IF (
            DIVIDE ( Terminations12MTD, Headcount12MTD ) = BLANK (),
            0,
            DIVIDE ( Terminations12MTD, Headcount12MTD )
        ),
        'Calendar'[Month Offset] &amp;gt; 0
    )
&lt;/LI-CODE&gt;
&lt;P&gt;Also, there's no need to have multiple RETURNs in there. This only obscures the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, ALLSELECTED is a very complex function. The most complex function in whole DAX. Do you fully understand what it does? Do you know what shadow context is? I'll give you a hint that will save your life: Please never use in your code something the functionality of which you don't fully understand. If you do use it, you'll be having countless bugs, many of which you'll not be even aware of.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;D&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 18:07:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/951462#M10691</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-27T18:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: DAX VAR Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/954035#M10841</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your response, sorry for the late reply I have been away this weekend.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a dummy file which should be of use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A title="Turnover Test" href="https://g8education-my.sharepoint.com/:u:/g/personal/james_pearce_g8education_edu_au/EdsUZJOx3_NDl1gFuCyyqssBj_l7ZlWFiSuoR8inIBn70Q?e=uwOaaY" target="_self"&gt;Turnover Test&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My aim is to reduce the Centre Turnover KPI to just one Measure instead of having five.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp; no I am not fully aware of ALLSELECTED and its limitations so more than happy for that to be adjusted.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Mar 2020 06:03:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/954035#M10841</guid>
      <dc:creator>JP8991</dc:creator>
      <dc:date>2020-03-01T06:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: DAX VAR Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/955654#M10947</link>
      <description>Hi there. Please read this about ALLSELECTED: &lt;A href="https://www.sqlbi.com/articles/the-definitive-guide-to-allselected/" target="_blank"&gt;https://www.sqlbi.com/articles/the-definitive-guide-to-allselected/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;It'll give you an idea about the function and why it should be used wisely.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Mon, 02 Mar 2020 17:19:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/955654#M10947</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-02T17:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: DAX VAR Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/968049#M11515</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp; Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions as to how I can improve these Measures?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My aim is to have them reduced from 5 to 1 and refrain from using ALLSELECTED if that isn't advisable, I provided a sample file in an earlier post.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 05:36:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-VAR-Function/m-p/968049#M11515</guid>
      <dc:creator>JP8991</dc:creator>
      <dc:date>2020-03-11T05:36:15Z</dc:date>
    </item>
  </channel>
</rss>

