Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jdoshi65
Frequent Visitor

How to calculate total of respective Year or Month as selected in Filter

Hi Floks,

 

I'm trying to build Employee Attriation Dashboard. I have following SharePoint list structure where we are managing employee details:

Employee IDEmployee NameDesignationDepartmentLocationHire DateTermination Date
E101Emp Name 1 Dept AUS1/1/20012 
E102Emp Name 2 Dept BIndia5/1/2013 
E103Emp Name 3 Dept CGermany5/5/20142/4/2015
E104Emp Name 4 Dept AUK8/2/2014 
E105Emp Name 5 Dept DUS8/5/2014 
E106Emp Name 6 Dept BIndia8/8/20145/12/2015
E107Emp Name 7 Dept CGermany9/12/2014 
E108Emp Name 8 Dept AUK3/3/2015 
E109Emp Name 9 Dept BUS4/18/2015 
E110Emp Name 10 Dept DIndia6/8/2015 
E111Emp Name 11 Dept EGermany8/8/20155/5/2016
E112Emp Name 12 Dept BUK9/9/2015 
E113Emp Name 13 Dept CUS1/10/2016 
E114Emp Name 14 Dept CIndia4/18/20162/8/2017
E115Emp Name 15 Dept BGermany8/15/2016 
E116Emp Name 16 Dept AUK12/5/2016 
E117Emp Name 17 Dept DUS1/9/2017 
E118Emp Name 18 Dept BIndia1/20/2017 
E119Emp Name 19 Dept BGermany2/2/2017 
E120Emp Name 20 Dept CUK2/14/2017 

 

I tried to create measure of Emp Head count at the time of starting of respective period.

 

Total Employee = CALCULATE (COUNTROWS( Employee ), FILTER ( Employee, Employee[HireDate] <= CALCULATE ( MAX ( 'Date Dimension'[Date] ), FILTER( Employee, Employee[HireDate] >= MIN( 'Date Dimension'[Date])))))

Above formula returns the total of employee in the organization for the selected period and value is right.

 

Now, I tried to calculate the # of New Hires however I didn't able to figure it out to calculate only new employee joined for that particualr period.

 

Any help will be appricieted.

 

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

@jdoshi65

Another way to do this would be to create a New Table (click New Table on the Modeling tab)

I call this the @OwenAuger GENERATE method Smiley Happy

Employee Hiring History = 
SUMMARIZE (
    GENERATE (
        EmployeesTable,
        CALCULATETABLE (
            VALUES ( 'CalendarTable'[Date] ),
            DATESBETWEEN (
                'CalendarTable'[Date],
                EmployeesTable[Hire Date],
                EmployeesTable[Termination Date]
            )
        )
    ),
    EmployeesTable[Employee Name],
    'CalendarTable'[Date]
)

Here's the Measure for this table

Active Employees = 
CALCULATE (
    DISTINCTCOUNT ( 'Employee Hiring History'[Employee Name] ),
    FILTER (
        ALL ( 'Employee Hiring History'[Date] ),
        'Employee Hiring History'[Date] <= MAX ( 'Employee Hiring History'[Date] )
    )
)

This method also works and on the daily level both SUMMARIZE and USERELATIONSHIP produce the same results

However when you move up to the monthly level - people that have been terminated this month are still counted for the whole month with the SUMMARIZE method

Case in point Feb 2017 Emp 14 was terminated however will be included with the summarize method!

So which way you go will depend in your requirement... Smiley Happy

USERELATIONSHIP - ActiveCount vs SUMMARIZE.png

USERELATIONSHIP - ActiveCount vs SUMMARIZE2.png

View solution in original post

2 REPLIES 2
Sean
Community Champion
Community Champion

@jdoshi65

Here's one way of doing this...

1) Create a CalendarTable

2) Relate Hire Date to CalendarTabele[Date] and then Termination Date to CalendarTable[Date] also

(second relationship will be inactive indcated by a dotted line)

3) create these 4 Measures

Hired = COUNTA ( EmployeesTable[Hire Date] )

Terminated = 
CALCULATE (
    COUNTA ( EmployeesTable[Termination Date] ),
    USERELATIONSHIP ( CalendarTable[Date], EmployeesTable[Termination Date] )
)
Balance = [Hired] - [Terminated]

Overall Current Employees = 
CALCULATE (
    [Balance],
    FILTER (
        ALL(CalendarTable[Date]),
        CalendarTable[Date] <= MAX ( CalendarTable[Date] )
    )
)

Here's the result...

 

USERELATIONSHIP - ActiveCount.gif

 

Hope this helps! Smiley Happy

Sean
Community Champion
Community Champion

@jdoshi65

Another way to do this would be to create a New Table (click New Table on the Modeling tab)

I call this the @OwenAuger GENERATE method Smiley Happy

Employee Hiring History = 
SUMMARIZE (
    GENERATE (
        EmployeesTable,
        CALCULATETABLE (
            VALUES ( 'CalendarTable'[Date] ),
            DATESBETWEEN (
                'CalendarTable'[Date],
                EmployeesTable[Hire Date],
                EmployeesTable[Termination Date]
            )
        )
    ),
    EmployeesTable[Employee Name],
    'CalendarTable'[Date]
)

Here's the Measure for this table

Active Employees = 
CALCULATE (
    DISTINCTCOUNT ( 'Employee Hiring History'[Employee Name] ),
    FILTER (
        ALL ( 'Employee Hiring History'[Date] ),
        'Employee Hiring History'[Date] <= MAX ( 'Employee Hiring History'[Date] )
    )
)

This method also works and on the daily level both SUMMARIZE and USERELATIONSHIP produce the same results

However when you move up to the monthly level - people that have been terminated this month are still counted for the whole month with the SUMMARIZE method

Case in point Feb 2017 Emp 14 was terminated however will be included with the summarize method!

So which way you go will depend in your requirement... Smiley Happy

USERELATIONSHIP - ActiveCount vs SUMMARIZE.png

USERELATIONSHIP - ActiveCount vs SUMMARIZE2.png

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.