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
Anonymous
Not applicable

Help Calculating & Summarizing the % of hours of absence per employee [UPDATED]

Hi all,

so I have the following data (this is a simplified and ramdomized sample).

 

I need to calculate the % of time an employee has been absent during 2018.

 

The employees in my example are expected to work different amounts of hours [TARGET HOURS] over the 12 months , based on the duration of their contracts.

 

I need to build a pivot where I can see a summary BY DIVISION of the % of time people were absent.

 

 

YEAR 2018
          DIVISION
                    EMPLOYEE ID

 

My problem is that if I use the simple "calculated field" the summary is not correct since Excel does not sum the total number of hours all employees with absences, by  division, are supposed to work.

 

Example : there are 2 employees in operations that were absent, therefore the % should be calculated on 2500 (1800+700) hours , the sum of the total hours for both of them.

 

Sample Data

 

Employeed IDDivisionDate AbsentHours AbsentTarget hours
10138Operations27/01/201841800
10138Operations28/01/2018121800
10021Marketing28/01/2018121000
10021Marketing29/01/2018121000
10138Operations29/01/201821800
10135Procurement29/01/201812900
10021Marketing30/01/2018121000
10138Operations30/01/201831800
10135Procurement30/01/201812900
10138Operations05/02/2018121800
10135Procurement05/02/201812900
10138Operations06/02/2018121800
10135Procurement06/02/20186900
10135Procurement07/02/20185900
10138Operations07/02/2018121800
10135Procurement08/02/201812900
10138Operations08/02/2018121800
10138Operations12/02/2018121800
10135Procurement12/02/20188900
10138Operations14/02/2018121800
10135Procurement14/02/201812900
10138Operations15/02/2018121800
10138Operations16/02/2018121800
10063Sales23/02/2018121800
10138Operations23/02/201831800
10063Sales24/02/2018121800
10138Operations24/02/2018121800
10138Operations25/02/2018121800
10063Sales25/02/2018121800
10084Operations04/05/201812700
10084Operations05/05/20189700
10084Operations06/05/201812700
1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Here we go.

Measure = 
VAR targ =
    SUMX (
        VALUES ( 'Table'[Employeed ID] ),
        CALCULATE (
            MAX ( 'Table'[Target hours] ),
            ALLEXCEPT ( 'Table', 'Table'[Date Absent].[Year], 'Table'[Employeed ID] )
        )
    )
VAR su =
    SUM ( 'Table'[Hours Absent] )
RETURN
    DIVIDE ( su, targ )

Capture.PNG

 

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

4 REPLIES 4
v-frfei-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Here we go.

Measure = 
VAR targ =
    SUMX (
        VALUES ( 'Table'[Employeed ID] ),
        CALCULATE (
            MAX ( 'Table'[Target hours] ),
            ALLEXCEPT ( 'Table', 'Table'[Date Absent].[Year], 'Table'[Employeed ID] )
        )
    )
VAR su =
    SUM ( 'Table'[Hours Absent] )
RETURN
    DIVIDE ( su, targ )

Capture.PNG

 

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Dear @v-frfei-msft  Frank,

 

thank you so so much for your help! 😎

 

Unfortunately due to my lack of precision, this turned into quite and adventure for me, since I realised I posted this issue in the wrong forum, I am using PowerBI in Excel 2016, not BI Desktop!

 

I did manage to get it to work, changing things a bit since I am very new on all this.

 

I also realised it was wrong to sum together the total hours for both years (18&19) so I did 2 separate files.

 

I marked your post as solution , but the actual code I used in Excel DataModel is this:

 

Pct Time Absnt 19:=
DIVIDE(
SUM(Report_2019[Hours Absent]), 
SUMX(
VALUES(Report_2019[Employee ID]), 
CALCULATE(
MAX([Hours Target 19]), 
ALLEXCEPT(Report_2019,Report_2019[Year],Report_2019[Employee ID]))))

 

One last question, as I am still studying your code, what is the "ALLEXCEPT" formula doing?

Anonymous
Not applicable

@Anonymous Please try below measure.

Measure = 
VAR _countofEmp = CALCULATE(DISTINCTCOUNT('Table'[Employeed ID]),ALLEXCEPT('Table','Table'[Division],'Table'[Date Absent].[Year]))
VAR _expectedHours =  _countofEmp*1800
VAR _absentHours = CALCULATE(SUM('Table'[Hours Absent]),ALLEXCEPT('Table','Table'[Division],'Table'[Date Absent].[Year]))
RETURN DIVIDE(_absentHours,_expectedHours,0)

Please let me know if you have any question. If it helps accept as solution. 

Anonymous
Not applicable

Dear @Anonymous , once again thank you so so much for the prompt and kind reply.

 

I realized a few moments ago that my question was not formulated correctly and I have updated the original post.

 

I gave the wrong information.

 

The employees have  different target total working hours for the year.

 

Some of them worked 12 months, but some others worked less.

 

So I have now changed the example data in the original post and I am also copying the same table here below.

 

Would you please be so kind to help me once more?

 

Employeed IDDivisionDate AbsentHours AbsentTarget hours
10138Operations27/01/201841800
10138Operations28/01/2018121800
10021Marketing28/01/2018121000
10021Marketing29/01/2018121000
10138Operations29/01/201821800
10135Procurement29/01/201812900
10021Marketing30/01/2018121000
10138Operations30/01/201831800
10135Procurement30/01/201812900
10138Operations05/02/2018121800
10135Procurement05/02/201812900
10138Operations06/02/2018121800
10135Procurement06/02/20186900
10135Procurement07/02/20185900
10138Operations07/02/2018121800
10135Procurement08/02/201812900
10138Operations08/02/2018121800
10138Operations12/02/2018121800
10135Procurement12/02/20188900
10138Operations14/02/2018121800
10135Procurement14/02/201812900
10138Operations15/02/2018121800
10138Operations16/02/2018121800
10063Sales23/02/2018121800
10138Operations23/02/201831800
10063Sales24/02/2018121800
10138Operations24/02/2018121800
10138Operations25/02/2018121800
10063Sales25/02/2018121800
10084Operations04/05/201812700
10084Operations05/05/20189700
10084Operations06/05/201812700

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.