<?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: Need Help to calculate employee head count for last 12 month in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474666#M28044</link>
    <description>&lt;P&gt;Sorry, but what do you mean by "not working"? The code takes the last visible date in 'DimDate' (this must be marked as a date table in the model and you have to use this table in the visual, not any other date field from any other table), checks if there are enough days to move back 12 months from the last visible date in the current context, moves back 12 months if possible and calculates the number of rows in 'HR' which are filtered by these 12 months. So, the code does exactly what you want. I can't see your pbix becasue I can't do it at work due to policies.&lt;/P&gt;</description>
    <pubDate>Wed, 04 Nov 2020 14:54:36 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-11-04T14:54:36Z</dc:date>
    <item>
      <title>Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1461033#M27549</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to plot a trend line where I need to show the last 12-month employee headcount base on the selection (Relative slicer max date). I've HR fact table and date dimension joined based on employee &lt;STRONG&gt;date of joining.&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've created DAX to calculate HC (Headcount) based on date selection(Max date from a relative slicer), it's working fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;HC = 

VAR MaxDate =
    MAX ( 'DimDate'[Date] )
VAR EmpCnt =
    CALCULATE ( 
        COUNTROWS (
            CALCULATETABLE ( 'HR', 'HR'[DateOfJoining] &amp;lt;= MaxDate, ALL ( 'DimDate' ) )
        ),
        (
            ISBLANK ( 'HR'[TerminationDate] )
                || 'HR'[TerminationDate] &amp;gt; MaxDate
        )
    )
RETURN
    IF ( ISBLANK ( EmpCnt ), 0, EmpCnt )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the same report, I need to show the same measure i.e. HC but for the last 12-months. For example, if I choose to show the last two calendar years from relative slicer then Dax should pick the max date from slicer and show the last 12 months from that max date.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Here is the link PBIX file.&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.dropbox.com/s/hx47zfghx77k0zh/HR%20-%20Employee%20Overview%20Last%2012%20Month.pbix?dl=0" target="_self"&gt;Link&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 15:38:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1461033#M27549</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-02T15:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1461542#M27576</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt; , Try like &lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;HC = 
VAR _Max1 =
    MAXX ( allselected('DimDate'), 'DimDate'[Date] )
VAR _Max = date(year(_max1), month(_max1)-12, day(_max1))	
VAR MaxDate =
    MAX ( 'DimDate'[Date] )
VAR EmpCnt =
    CALCULATE ( 
        COUNTROWS (
            CALCULATETABLE ( 'HR', 'HR'[DateOfJoining] &amp;lt;= MaxDate, ALL ( 'DimDate' ) )
        ),
        (
            ISBLANK ( 'HR'[TerminationDate] )
                || 'HR'[TerminationDate] &amp;gt; MaxDate
        )
    )
RETURN
    IF ( ISBLANK ( EmpCnt ) , 0, if(max('DimDate'[Date])&amp;gt;=_Max, EmpCnt, blank() ))&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 28 Oct 2020 16:53:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1461542#M27576</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2020-10-28T16:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1462362#M27619</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="148838" data-lia-user-login="amitchandak" class="lia-mention lia-mention-user"&gt;amitchandak&lt;/a&gt;&amp;nbsp;This DAX is Working fine On the Selection Of Last 2 Or 3 years.But this DAX is not Working On the Selection Of "Last 2 Month", "Last 3 month", "Last 2 Week " ,"Last 3 Weeks"&amp;nbsp; , "Last&amp;nbsp; 2 Days " and On&amp;nbsp; "This Days", "this Month" etc.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 03:13:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1462362#M27619</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-29T03:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1466862#M27759</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="148838" data-lia-user-login="amitchandak" class="lia-mention lia-mention-user"&gt;amitchandak&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Furthur assistant, please. Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 31 Oct 2020 12:22:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1466862#M27759</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-31T12:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474247#M28026</link>
      <description>&lt;P&gt;Need Help to calculate employee head count for last 12 month.Please help.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 11:29:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474247#M28026</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-04T11:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474616#M28042</link>
      <description>&lt;LI-CODE lang="javascript"&gt;// Assumption:
// The calendar, DimDate, starts
// on 1 Jan of some year.

[HC 12M] =
VAR __lastVisibleDate =
    MAX( 'DimDate'[Date] )
var __veryFirstYearInCalendar =
    CALCULATE(
        min( 'DimDate'[Year] ), // Year must be an int
        all( 'DimDate' )
    )
// This is the minimum date after or on which
// you can calculate the head count. If the date
// is before this day, there are not enough days
// to go back (you have to have 1 full year).
var __firstDay =
    date( __veryFirstYearInCalendar, 12, 31 )
VAR __employeeCount =
    if( __lastVisibleDate &amp;gt;= __firstDay,
        0 + CALCULATE(
            COUNTROWS( 'HR'),
            OR(
                ISBLANK( 'HR'[TerminationDate] ),
                'HR'[TerminationDate] &amp;gt; __lastVisibleDate
            ),
            DATESINPERIOD(
                'DimDate'[Date],
                __lastVisibleDate,
                -1,
                year
            )
        )
    )
RETURN
    __employeeCount
    
// Please note that this measure distinguishes between
// 2 cases:
// 1) If there are enough days to calculate
// the measure but the count is 0, then 0 is returned.
// 2) If there are not enough days to calculate
// the measure, BLANK is returned.&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 04 Nov 2020 14:31:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474616#M28042</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-04T14:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474653#M28043</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;.I have used your measure but this not working on relative Slicer.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I need last 12 month HC.Whatever we select from Slicer i.e last 2 days,3 days ,last 3 years or last 2 months.Next month.or year etc&lt;/P&gt;&lt;P&gt;I have attached .pbix file please download &amp;amp; sugguest me solution.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 14:44:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474653#M28043</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-04T14:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474666#M28044</link>
      <description>&lt;P&gt;Sorry, but what do you mean by "not working"? The code takes the last visible date in 'DimDate' (this must be marked as a date table in the model and you have to use this table in the visual, not any other date field from any other table), checks if there are enough days to move back 12 months from the last visible date in the current context, moves back 12 months if possible and calculates the number of rows in 'HR' which are filtered by these 12 months. So, the code does exactly what you want. I can't see your pbix becasue I can't do it at work due to policies.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 14:54:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474666#M28044</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-04T14:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474673#M28046</link>
      <description>&lt;P&gt;It might be that you want something different than the algorithm I gave you but then you have to be very specific about what it is you want.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 14:56:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474673#M28046</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-04T14:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474682#M28048</link>
      <description>&lt;P&gt;I have attached .pbix in my post.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 14:59:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474682#M28048</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-04T14:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help to calculate employee head count for last 12 month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474688#M28051</link>
      <description>&lt;P&gt;&lt;EM&gt;And I tell you that I can't open and see it because I'm at work and my Company does not allow to view such things.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 15:01:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-Help-to-calculate-employee-head-count-for-last-12-month/m-p/1474688#M28051</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-04T15:01:29Z</dc:date>
    </item>
  </channel>
</rss>

