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

Need help with average per day functions to treat "half days" and "full days"

Hello,

 

I am building a report for my organization's timesheets. Users submit their hours through the system and I get access to all the data. I have a page per user displaying various information.

The problem I am facing is related to average worked hours per day.

 

My formula is quite simple:

average_hours_per_day = AVERAGEX( VALUES ('username'[date]), 'username'[sum_hours])

(username represents a user's table containing their timesheet submissions)

 

My problem comes from the fact that I exclude user's vacation days, days off for sickness etc from the average, as to not impact it with meaningless data. I have a simple filter that checks the category of each submission, and if it matches "holidays", "sick leave" it gets exluded (so there is no submission for that date).

 

This worked fine until I realized that it wouldn't work properly in the case of a user taking a half day off. The half day will be excluded but the submissions for the other half will be considered in the average. This will lower the user's average, because it is considered a full day in the formula above, even if the user only worked half of a normal day.

 

Here is some sample data to illustrate this:

 

 

average.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Based on this data, the average worked hours for this user (excluding days off) would be:

(2+2 + 4 + 4 + 4 + 4 + 4 + 4) / 3.5 = 8 hours per day on average (3 days + 0.5 days)

But my formula considers it to be 4 days:

28/4 = 7 hours per day on average

 

Are there any functions that could help me here ? Or any other ideas ?

I have no idea how to fix this at the moment.

 

Thank you for reading.

 

Valentin

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

 

Based on your information, I have made a test.

 

Following your logic, you could try the formulas below.

 

Table =
SUMMARIZE (
    'Table1',
    'Table1'[Date],
    "hours", CALCULATE (
        SUM ( Table1[Duration] ),
        FILTER (
            Table1,
            'Table1'[Activity] = "Work"
                && 'Table1'[Date] = EARLIER ( 'Table1'[Date] )
        )
    )
)

Measure =
VAR a =
    CALCULATE ( SUM ( 'Table'[hours] ) )
RETURN
    IF ( a = 0, 0, IF ( AND ( a > 0, a < 8 ), 0.5, 1 ) )

Average work hours = 
CALCULATE(SUM('Table'[hours]))/SUMX('Table',[Measure])

 

Here is the result.

 

output.PNG

More details, please refer to my attachment.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

 

Based on your information, I have made a test.

 

Following your logic, you could try the formulas below.

 

Table =
SUMMARIZE (
    'Table1',
    'Table1'[Date],
    "hours", CALCULATE (
        SUM ( Table1[Duration] ),
        FILTER (
            Table1,
            'Table1'[Activity] = "Work"
                && 'Table1'[Date] = EARLIER ( 'Table1'[Date] )
        )
    )
)

Measure =
VAR a =
    CALCULATE ( SUM ( 'Table'[hours] ) )
RETURN
    IF ( a = 0, 0, IF ( AND ( a > 0, a < 8 ), 0.5, 1 ) )

Average work hours = 
CALCULATE(SUM('Table'[hours]))/SUMX('Table',[Measure])

 

Here is the result.

 

output.PNG

More details, please refer to my attachment.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.