<?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 Need help with a DAX measure (Headcount) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-DAX-measure-Headcount/m-p/3657765#M141728</link>
    <description>&lt;P&gt;Hello everyone!&lt;/P&gt;&lt;P&gt;I'm excited to make my first post on this forum and to be a part of the Power BI community.&lt;/P&gt;&lt;P&gt;I've been exploring Power BI for about a year and am encountering a challenge with the following formula:&lt;/P&gt;&lt;P&gt;Headcount Status =&lt;BR /&gt;VAR SelectedDate = MAX('DateDimensionTable'[Date])&lt;BR /&gt;VAR LatestStatusPerEmployee =&lt;BR /&gt;CALCULATETABLE(&lt;BR /&gt;SUMMARIZE( /*to summarize by employee ID*/&lt;BR /&gt;'FactsTable',&lt;BR /&gt;'FactsTable'[EMPLOYEE_EMPLOYEEID],&lt;BR /&gt;"LatestStatusChange", MAX('FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP]),&amp;nbsp;&lt;BR /&gt;"LatestStatus", CALCULATE(MAX('FactsTable'[EMPLOYMENTSTATUS_LONGNAME]), /*is the column where the status are*/&lt;BR /&gt;USERELATIONSHIP('DateDimensionTable'[Date], 'FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP]),&lt;BR /&gt;FILTER(ALL('FactsTable'),&lt;BR /&gt;'FactsTable'[EMPLOYEE_EMPLOYEEID] = EARLIER('FactsTable'[EMPLOYEE_EMPLOYEEID])&lt;BR /&gt;&amp;amp;&amp;amp; 'FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP] == [LatestStatusChange]))&lt;BR /&gt;),&lt;BR /&gt;USERELATIONSHIP('DateDimensionTable'[Date], 'FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP])&lt;BR /&gt;)&lt;BR /&gt;VAR CountCondition =&lt;BR /&gt;FILTER(&lt;BR /&gt;LatestStatusPerEmployee,&lt;BR /&gt;[LatestStatus] IN {"Status 1", "status2", "status3"}&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;COUNTROWS(CountCondition)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;My objective is to create a dynamic headcount measure that tracks employee status changes over time. For instance, using a slicer, if I filter to December 31st, an employee who was in "Status 1" in January and moved to "Status 2" in December should be reflected correctly in the breakdown. However, I'm facing two main issues:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The overall headcount seems incorrect and tends to decrease as I go back in time, even though there should be variations.&lt;/LI&gt;&lt;LI&gt;In visualizations, employee statuses aren't updating correctly. For example, if an employee's status changed in August, that status remains fixed in all subsequent views.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;In my model, the primary connection is between the date in my dimension table and the original hire date in the fact table. I've attempted to use a USERELATIONSHIP in the DAX to incorporate a link with the status creation timestamp, but this hasn't resolved the issue.&lt;/P&gt;&lt;P&gt;I'm open to any questions or suggestions for further clarification. Thank you in advance for your help!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 24 Jan 2024 17:29:54 GMT</pubDate>
    <dc:creator>alexflo188</dc:creator>
    <dc:date>2024-01-24T17:29:54Z</dc:date>
    <item>
      <title>Need help with a DAX measure (Headcount)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-DAX-measure-Headcount/m-p/3657765#M141728</link>
      <description>&lt;P&gt;Hello everyone!&lt;/P&gt;&lt;P&gt;I'm excited to make my first post on this forum and to be a part of the Power BI community.&lt;/P&gt;&lt;P&gt;I've been exploring Power BI for about a year and am encountering a challenge with the following formula:&lt;/P&gt;&lt;P&gt;Headcount Status =&lt;BR /&gt;VAR SelectedDate = MAX('DateDimensionTable'[Date])&lt;BR /&gt;VAR LatestStatusPerEmployee =&lt;BR /&gt;CALCULATETABLE(&lt;BR /&gt;SUMMARIZE( /*to summarize by employee ID*/&lt;BR /&gt;'FactsTable',&lt;BR /&gt;'FactsTable'[EMPLOYEE_EMPLOYEEID],&lt;BR /&gt;"LatestStatusChange", MAX('FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP]),&amp;nbsp;&lt;BR /&gt;"LatestStatus", CALCULATE(MAX('FactsTable'[EMPLOYMENTSTATUS_LONGNAME]), /*is the column where the status are*/&lt;BR /&gt;USERELATIONSHIP('DateDimensionTable'[Date], 'FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP]),&lt;BR /&gt;FILTER(ALL('FactsTable'),&lt;BR /&gt;'FactsTable'[EMPLOYEE_EMPLOYEEID] = EARLIER('FactsTable'[EMPLOYEE_EMPLOYEEID])&lt;BR /&gt;&amp;amp;&amp;amp; 'FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP] == [LatestStatusChange]))&lt;BR /&gt;),&lt;BR /&gt;USERELATIONSHIP('DateDimensionTable'[Date], 'FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP])&lt;BR /&gt;)&lt;BR /&gt;VAR CountCondition =&lt;BR /&gt;FILTER(&lt;BR /&gt;LatestStatusPerEmployee,&lt;BR /&gt;[LatestStatus] IN {"Status 1", "status2", "status3"}&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;COUNTROWS(CountCondition)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;My objective is to create a dynamic headcount measure that tracks employee status changes over time. For instance, using a slicer, if I filter to December 31st, an employee who was in "Status 1" in January and moved to "Status 2" in December should be reflected correctly in the breakdown. However, I'm facing two main issues:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The overall headcount seems incorrect and tends to decrease as I go back in time, even though there should be variations.&lt;/LI&gt;&lt;LI&gt;In visualizations, employee statuses aren't updating correctly. For example, if an employee's status changed in August, that status remains fixed in all subsequent views.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;In my model, the primary connection is between the date in my dimension table and the original hire date in the fact table. I've attempted to use a USERELATIONSHIP in the DAX to incorporate a link with the status creation timestamp, but this hasn't resolved the issue.&lt;/P&gt;&lt;P&gt;I'm open to any questions or suggestions for further clarification. Thank you in advance for your help!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 24 Jan 2024 17:29:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-DAX-measure-Headcount/m-p/3657765#M141728</guid>
      <dc:creator>alexflo188</dc:creator>
      <dc:date>2024-01-24T17:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a DAX measure (Headcount)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-DAX-measure-Headcount/m-p/3658794#M141767</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="679742" data-lia-user-login="alexflo188" class="lia-mention lia-mention-user"&gt;alexflo188&lt;/a&gt;&amp;nbsp;&lt;SPAN&gt;you can try using the following DAX measure:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Headcount Status = 
VAR SelectedDate = MAX('DateDimensionTable'[Date])
VAR LatestStatusPerEmployee =
CALCULATETABLE(
    SUMMARIZE(
        'FactsTable',
        'FactsTable'[EMPLOYEE_EMPLOYEEID],
        "LatestStatusChange", MAX('FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP]), 
        "LatestStatus", CALCULATE(MAX('FactsTable'[EMPLOYMENTSTATUS_LONGNAME]),
            USERELATIONSHIP('DateDimensionTable'[Date], 'FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP])
        )
    ),
    USERELATIONSHIP('DateDimensionTable'[Date], 'FactsTable'[EMPLOYEEEMPLOYMENTSTATUS_CREATEDTIMESTAMP])
)
VAR CountCondition =
FILTER(
    LatestStatusPerEmployee,
    [LatestStatus] IN {"Status 1", "status2", "status3"}
)
RETURN
COUNTROWS(CountCondition)&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;This measure calculates the headcount based on the latest status change for each employee. It also filters the results to only include employees with “Status 1”, “status2”, or “status3”. You can use this measure in a PivotTable to display the headcount by date.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the steps to create a disconnected table:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a new table with a single column that contains all the dates you want to filter by.&lt;/LI&gt;&lt;LI&gt;Create a relationship between the new table and the DateDimensionTable.&lt;/LI&gt;&lt;LI&gt;Use the new table as a slicer in your visualizations.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;By using a disconnected table, you can filter the data by date without affecting the overall headcount.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;Let me know if this works for you.&amp;nbsp;@ me in replies, or I'll lose your thread!!!&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;BR /&gt;&lt;U&gt;Note:&lt;/U&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;If this post is helpful, please mark it as the&amp;nbsp;&lt;STRONG&gt;solution&lt;/STRONG&gt;&amp;nbsp;to help others find it easily. Also, if my answers contribute to a solution, show your appreciation by giving it a&amp;nbsp;&lt;STRONG&gt;thumbs up&lt;/STRONG&gt;!&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 25 Jan 2024 05:39:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-DAX-measure-Headcount/m-p/3658794#M141767</guid>
      <dc:creator>DallasBaba</dc:creator>
      <dc:date>2024-01-25T05:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a DAX measure (Headcount)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-DAX-measure-Headcount/m-p/3660699#M141851</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="446607" data-lia-user-login="DallasBaba" class="lia-mention lia-mention-user"&gt;DallasBaba&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for you suggestion. That being said, could you explain me why I should use the expression USERELATIONSHIP in the measure if I'm not using the connection from the datedimension table and primary fact table?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance ! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alex,&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 14:30:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-with-a-DAX-measure-Headcount/m-p/3660699#M141851</guid>
      <dc:creator>alexflo188</dc:creator>
      <dc:date>2024-01-25T14:30:25Z</dc:date>
    </item>
  </channel>
</rss>

