<?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 Average Count in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Count/m-p/3544542#M136286</link>
    <description>&lt;P&gt;Hi folks. People Have been amazing so far helping me understand what to do. Hoping we can get this next bit running ok.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I work out Current EMployees using this piece of code which works great:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Current Employees = CALCULATE(COUNTx(FILTER(STAFFMASTER,STAFFMASTER[Current Employment: Start Date]&amp;lt;=max('Date'[Date]) &amp;amp;&amp;amp; (ISBLANK(staffmaster[End Date]) || staffmaster[End Date]&amp;gt;max('Date'[Date]))),(STAFFMASTER[Unique Id])),CROSSFILTER(STAFFMASTER[Current Employment: Start Date],'Date'[Date],None))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Then I work out Employees at a specific date using this piece:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Employed Staff Count = 
 var minD = MIN('Date'[Date])
  var maxD = MAX('Date'[Date])
  RETURN CALCULATE(
    DISTINCTCOUNT('STAFFMASTER'[Unique ID]),
    'STAFFMASTER'[Current Employment: Start Date] &amp;lt;= minD &amp;amp;&amp;amp;
    ( 'STAFFMASTER'[End Date] &amp;gt;= maxD || ISBLANK('STAFFMASTER'[End Date]) ),
    CROSSFILTER('Date'[Date], STAFFMASTER[Current Employment: Start Date], None)
  )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I try to do a simple measure for example of&amp;nbsp;&lt;/P&gt;&lt;P&gt;Average Staff = ([current employees]+[Employed Staff Count])/2&amp;nbsp;&lt;/P&gt;&lt;P&gt;then I get a wrong answer because the measure doesnt have the same filters active as the measures in those code snippets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I then try and resolve this by doing a measure like this -&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Average Staff = 
VAR CurrentEmps = CALCULATE(COUNTx(FILTER(STAFFMASTER,STAFFMASTER[Current Employment: Start Date]&amp;lt;=max('Date'[Date]) &amp;amp;&amp;amp; (ISBLANK(staffmaster[End Date]) || staffmaster[End Date]&amp;gt;max('Date'[Date]))),(STAFFMASTER[Unique Id])),CROSSFILTER(STAFFMASTER[Current Employment: Start Date],'Date'[Date],None))
VAR Employed = 
 var minD = MIN('Date'[Date])
  var maxD = MAX('Date'[Date])
  RETURN CALCULATE(
    DISTINCTCOUNT('STAFFMASTER'[Unique ID]),
    'STAFFMASTER'[Current Employment: Start Date] &amp;lt;= minD &amp;amp;&amp;amp;
    ( 'STAFFMASTER'[End Date] &amp;gt;= maxD || ISBLANK('STAFFMASTER'[End Date]) ),
    CROSSFILTER('Date'[Date], STAFFMASTER[Current Employment: Start Date], None)
  )

RETURN
    (CurrentEmps + Employed) / 2&lt;/LI-CODE&gt;&lt;P&gt;I get an incorrect answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions how to work this or even a simpler solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically the sum needs to be current staff+staff at a specific date / 2 which will give the average staff over that period.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Nov 2023 11:27:20 GMT</pubDate>
    <dc:creator>DH3612</dc:creator>
    <dc:date>2023-11-21T11:27:20Z</dc:date>
    <item>
      <title>Average Count</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Count/m-p/3544542#M136286</link>
      <description>&lt;P&gt;Hi folks. People Have been amazing so far helping me understand what to do. Hoping we can get this next bit running ok.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I work out Current EMployees using this piece of code which works great:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Current Employees = CALCULATE(COUNTx(FILTER(STAFFMASTER,STAFFMASTER[Current Employment: Start Date]&amp;lt;=max('Date'[Date]) &amp;amp;&amp;amp; (ISBLANK(staffmaster[End Date]) || staffmaster[End Date]&amp;gt;max('Date'[Date]))),(STAFFMASTER[Unique Id])),CROSSFILTER(STAFFMASTER[Current Employment: Start Date],'Date'[Date],None))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Then I work out Employees at a specific date using this piece:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Employed Staff Count = 
 var minD = MIN('Date'[Date])
  var maxD = MAX('Date'[Date])
  RETURN CALCULATE(
    DISTINCTCOUNT('STAFFMASTER'[Unique ID]),
    'STAFFMASTER'[Current Employment: Start Date] &amp;lt;= minD &amp;amp;&amp;amp;
    ( 'STAFFMASTER'[End Date] &amp;gt;= maxD || ISBLANK('STAFFMASTER'[End Date]) ),
    CROSSFILTER('Date'[Date], STAFFMASTER[Current Employment: Start Date], None)
  )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I try to do a simple measure for example of&amp;nbsp;&lt;/P&gt;&lt;P&gt;Average Staff = ([current employees]+[Employed Staff Count])/2&amp;nbsp;&lt;/P&gt;&lt;P&gt;then I get a wrong answer because the measure doesnt have the same filters active as the measures in those code snippets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I then try and resolve this by doing a measure like this -&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Average Staff = 
VAR CurrentEmps = CALCULATE(COUNTx(FILTER(STAFFMASTER,STAFFMASTER[Current Employment: Start Date]&amp;lt;=max('Date'[Date]) &amp;amp;&amp;amp; (ISBLANK(staffmaster[End Date]) || staffmaster[End Date]&amp;gt;max('Date'[Date]))),(STAFFMASTER[Unique Id])),CROSSFILTER(STAFFMASTER[Current Employment: Start Date],'Date'[Date],None))
VAR Employed = 
 var minD = MIN('Date'[Date])
  var maxD = MAX('Date'[Date])
  RETURN CALCULATE(
    DISTINCTCOUNT('STAFFMASTER'[Unique ID]),
    'STAFFMASTER'[Current Employment: Start Date] &amp;lt;= minD &amp;amp;&amp;amp;
    ( 'STAFFMASTER'[End Date] &amp;gt;= maxD || ISBLANK('STAFFMASTER'[End Date]) ),
    CROSSFILTER('Date'[Date], STAFFMASTER[Current Employment: Start Date], None)
  )

RETURN
    (CurrentEmps + Employed) / 2&lt;/LI-CODE&gt;&lt;P&gt;I get an incorrect answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions how to work this or even a simpler solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically the sum needs to be current staff+staff at a specific date / 2 which will give the average staff over that period.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 11:27:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Count/m-p/3544542#M136286</guid>
      <dc:creator>DH3612</dc:creator>
      <dc:date>2023-11-21T11:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Average Count</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Count/m-p/3544827#M136303</link>
      <description>&lt;P&gt;Hi, without investigating much about the logics about the calculation of 'Employed' and 'CurrentEmps' i assume your DAX formula will result not in an incorrect answer but in an error due to the fact you put two RETURN statement inside one DAX formula. Before thinking about the quality of your calculation i would try to run this instead:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VAR CurrentEmps =&lt;BR /&gt;CALCULATE (&lt;BR /&gt;COUNTX (&lt;BR /&gt;FILTER (&lt;BR /&gt;STAFFMASTER,&lt;BR /&gt;STAFFMASTER[Current Employment: Start Date] &amp;lt;= MAX ( 'Date'[Date] )&lt;BR /&gt;&amp;amp;&amp;amp; (&lt;BR /&gt;ISBLANK ( staffmaster[End Date] )&lt;BR /&gt;|| staffmaster[End Date] &amp;gt; MAX ( 'Date'[Date] )&lt;BR /&gt;)&lt;BR /&gt;),&lt;BR /&gt;( STAFFMASTER[Unique Id] )&lt;BR /&gt;),&lt;BR /&gt;CROSSFILTER ( STAFFMASTER[Current Employment: Start Date], 'Date'[Date], NONE )&lt;BR /&gt;)&lt;BR /&gt;VAR Employed =&lt;BR /&gt;CALCULATE (&lt;BR /&gt;DISTINCTCOUNT ( 'STAFFMASTER'[Unique ID] ),&lt;BR /&gt;'STAFFMASTER'[Current Employment: Start Date] &amp;lt;= MIN ( 'Date'[Date] )&lt;BR /&gt;&amp;amp;&amp;amp; (&lt;BR /&gt;'STAFFMASTER'[End Date] &amp;gt;= MAX ( 'Date'[Date] )&lt;BR /&gt;|| ISBLANK ( 'STAFFMASTER'[End Date] )&lt;BR /&gt;),&lt;BR /&gt;CROSSFILTER ( 'Date'[Date], STAFFMASTER[Current Employment: Start Date], NONE )&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;( CurrentEmps + Employed ) / 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Logics are the same as yours but in my opinion minD and maxD variables were not necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this will help you! Cheers!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 13:30:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Count/m-p/3544827#M136303</guid>
      <dc:creator>fbura</dc:creator>
      <dc:date>2023-11-21T13:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Average Count</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Count/m-p/3544877#M136307</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I amended to use the code you provided, but get the same answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in the example I am using, I have the date filtered to 31/10/22, and the staff count there is 1789 (Employed Staff Count). The staff count today is 1996 (Current Staff). So adding those together then dividing by two should be 1892.5. But the result seems to be 1788.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 13:49:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Count/m-p/3544877#M136307</guid>
      <dc:creator>DH3612</dc:creator>
      <dc:date>2023-11-21T13:49:44Z</dc:date>
    </item>
  </channel>
</rss>

