<?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: Employee Headcount history changes in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944285#M10228</link>
    <description>Because it's always best to use variables.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
    <pubDate>Sun, 23 Feb 2020 20:47:30 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-02-23T20:47:30Z</dc:date>
    <item>
      <title>Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/941035#M10030</link>
      <description>&lt;P&gt;I need a measure to calculate the employees that were actives in some period and there respective "Cost Center" (department), this measure can't "summarize" the total when no filter data is applied in the slicers, should show the actual (last) value from the last month in the context.&lt;BR /&gt;&lt;BR /&gt;I have one table of all Employess of the company, and in this table l have HireDate and FiredDate as well, and another table where I have the "history" changes of the employee, where I will have the start / end of the period that the employee was in determined Cost Center and his Rate, for example:&lt;BR /&gt;&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;From this Hist Table, I created a new Table (DAX) to explode the data between Start / End date, as bellow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With those data, I need one measure that will count if the employee is active in determined month/year and where we was allocated (Cost Center).&lt;BR /&gt;&lt;BR /&gt;I have something like the DAX bellow, but the results are not what I expected:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Headcount = 
DISTINCTCOUNT(Worker_Hist[Employee ID])&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Headcount_3 = 
CALCULATE( COUNTROWS( Worker_Hist ) ;
    FILTER ( VALUES( Worker_Hist[Start Date] ); Worker_Hist[Start Date] &amp;lt;= MAX ( Calendar[Date] ) );
    FILTER ( VALUES( Worker_Hist[End Date] ); OR ( Worker_Hist[End Date] &amp;gt; MAX ( Calendar[Date] ); 
        ISBLANK( Worker_Hist[End Date] ) ) ) )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Filter Year = 2019 / Month = All month&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The rules is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;If the employee is fired, in his last month he can't be counted as active. (in 03/2019, the ID 12223 should be "0";&lt;/LI&gt;&lt;LI&gt;If the employee just change the CC or "Rate", he has to be count as Active until the month of the "End Date" (From hist).&lt;/LI&gt;&lt;LI&gt;The total has to be the actual active at the select year/month, or if no filter is applied, the Total should be the actual actives employee.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I hope that someone could help me with that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advanced.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lúcio Andrade&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 14:25:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/941035#M10030</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-20T14:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/941568#M10055</link>
      <description>&lt;P&gt;I think the measure will work better if you check all conditions in one FILTER statement like this:&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;Headcount_4 =
CALCULATE (
    [HeadCount]
    FILTER (
        Worker_Hist;
        Worker_Hist[Start Date] &amp;lt;= MAX ( Calendar[Date] )
            &amp;amp;&amp;amp; (
                Worker_Hist[End Date] &amp;gt; MAX ( Calendar[Date] )
                    || ISBLANK ( Worker_Hist[End Date] )
            )
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Then of course you can add more logic to the filter as well.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 21:20:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/941568#M10055</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-20T21:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944260#M10214</link>
      <description>Anonymous&lt;/LI-USER&gt;, on what grounds do you claim that a complex filter will be better than a set of simple filters? I'll surprise you - the opposite is actually true because of the way CALCULATE works under the hood and because of what it is optimized for.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Sun, 23 Feb 2020 19:28:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944260#M10214</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-23T19:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944261#M10215</link>
      <description>The description of the measure, especially the rules, is foggy. Too foggy to be able to build something useful. One thing I've noticed is that in your Headcount_3 measure you have COUNTROWS( Worker_Hist ) which calculates the number of rows in Worker_Hist. THis is almost surely wrong.</description>
      <pubDate>Sun, 23 Feb 2020 19:36:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944261#M10215</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-23T19:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944267#M10216</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;As always I think it depends. But I have worked on some quite large tables before and then the FILTER function can really kill the performance (since it iterates the whole table). But yes, in this case the oppisite might be true since the filter in on VALUES([column]) and not on the whole table. But it's hard to tell without seeing the complete dataset and test the different ways to write the DAX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the reason I suggested to have one more complex filter in this case was that there might be logic that has dependencies on row level that cant be separated into many simple filters. So it had nothing to do with performance.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I might have been a little bit to fast writing an answer in this case, the requirements are a little bit hard to follow... But I think it can at least give a hint. But more logic (that I didn't understand) perhaps needs to be added.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 19:49:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944267#M10216</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-23T19:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944269#M10217</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Headcount =
var __maxVisibleDate = MAX ( Calendar[Date] )
var __minVisibleDate = MIN ( Calendar[Date] )
return
CALCULATE (
    DISTINCTCOUNT ( Worker_Hist[Employee ID] ),
    KEEPFILTERS ( Worker_Hist[Start Date] &amp;lt;= __minVisibleDate ),
    KEEPFILTERS ( Worker_Hist[End Date] &amp;gt; __maxVisibleDate )
) +
CALCULATE(
    DISTINCTCOUNT ( Worker_Hist[Employee ID] ),
    KEEPFILTERS ( Worker_Hist[Start Date] &amp;lt;= __minVisibleDate ),            
    KEEPFILTERS ( ISBLANK ( Worker_Hist[End Date] ) )
)
&lt;/LI-CODE&gt;
&lt;P&gt;I can't do any better because I don't fully understand the definition of the measure.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 19:52:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944269#M10217</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-23T19:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944271#M10219</link>
      <description>&lt;P&gt;Well,&amp;nbsp;Anonymous&lt;/LI-USER&gt;, sorry but you're not right. CALCULATE has been optimized to work with filters of the type:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table[column] = value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and nothing can be faster than this. There is some internal "magic" and tricks in the engine that make this true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can read about it on &lt;A href="http://www.sqlbi.com" target="_blank"&gt;www.sqlbi.com&lt;/A&gt; or in The Book by The Italians (The Ultimate Guide to DAX).&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>Sun, 23 Feb 2020 19:56:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944271#M10219</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-23T19:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944275#M10222</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;Yes, I'm aware of the CALCULATE magic on simple filters. But as far I have have understood it doesn't apply when you have filters with OR, MAX and other that was the case here. Then you cant use the simple CALCULATE([Measure], [Column]=xxx) format, you have to specify an implicit FILTER that is a lot slower. I think one of "the Italians" taught me this on my very first DAX course, but that was almost 10 years ago, so it might have been improved in newer versions? However, it is of cause better if you can have separate filters on columns instead of the whole table. But in some cases that could be hard because of the logic.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 20:26:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944275#M10222</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-23T20:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944278#M10224</link>
      <description>&lt;P&gt;Just to drive the point home...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The formula in the first post contains, for instance, such a line:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;FILTER ( VALUES( Worker_Hist[Start Date] ); Worker_Hist[Start Date] &amp;lt;= MAX ( Calendar[Date] ) )&lt;/LI-CODE&gt;
&lt;P&gt;This is nothing but&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;KEEPFILTERS( Worker_Hist[Start Date] &amp;lt;= value )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;which does happen to be a simple filter for CALCULATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apart from table[column] = value, the simple filters also contain the relational operators &amp;lt;, &amp;lt;=, &amp;gt;, &amp;gt;=.&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>Sun, 23 Feb 2020 20:28:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944278#M10224</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-23T20:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944281#M10225</link>
      <description>&lt;P&gt;Ok ,&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp; thank's for information. Happy to learn something new &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; The reason I thought this was still not optimized is the error message you get when trying to write the measure in the "simple format" (or in KEEPFILTERS):&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 20:40:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944281#M10225</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-23T20:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944285#M10228</link>
      <description>Because it's always best to use variables.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Sun, 23 Feb 2020 20:47:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/944285#M10228</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-23T20:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Employee Headcount history changes</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/945097#M10255</link>
      <description>&lt;P&gt;Dear Anonymous&lt;/LI-USER&gt;&amp;nbsp;and Anonymous&lt;/LI-USER&gt;&amp;nbsp;thanks for your post and comments.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Actually the measures do not achived what I need. I'm preparing a PB sample to share here, just making sure that confidential data will not be shared.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Lúcio&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 12:57:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Employee-Headcount-history-changes/m-p/945097#M10255</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-24T12:57:19Z</dc:date>
    </item>
  </channel>
</rss>

