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

How to add time to working days with its working hours, excluding weekend,holidays and no work hours

Hi everyone, this is my first post

i'm currently working on Power Bi for some simple reports that i need, im manipulating dates.

 

the problem is: i have a Initial date, but from that date i need to sum a time that can be minutes to a lots of hours, and the work hours of one day is 7:30 A.M to 17:30 P.M. The weekend and holidays must be validated also.

i read some post in community.powerbi , with the calendar + holidays table, but i can solve my problem at all, ths is the post i read https://community.powerbi.com/t5/Desktop/Add-working-days-to-a-date/td-p/146945

A
n example may be: 

InitialDate                            WorkHours        FinalDate
12/4/2018 17:20:00 P.M       7:50:00              12/5/2018 15:10:00 P.M

 

then, i have this problem, can you help me with this? thanks in advance

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

You can try to use following calculate column formula to calculate end date based on 'initial date' and 'work hours': 

EndDate =
VAR _todayRemain =
    TIME ( 17, 30, 00 )
        - MAX (
            TIME ( 7, 30, 00 ),
            MIN ( TIME ( 17, 30, 00 ), TIMEVALUE ( [InitialDate] ) )
        )
VAR _totalWorkhours =
    IF (
        WEEKDAY ( [InitialDate], 2 ) <= 5,
        [Work Hours] - _todayRemain,
        [Work Hours]
    )
VAR _workDays =
    IF (
        _totalWorkhours > 0,
        INT ( _totalWorkhours / 10 )
            + IF ( MOD ( _totalWorkhours, 10 ) > 0, 1, 0 ),
        0
    )
VAR _remaintime =
    _totalWorkhours
        - INT ( _totalWorkhours / 10 )
            * _totalWorkhours
VAR _holidayoffset =
    IF ( WEEKDAY ( [InitialDate], 2 ) >= 5, 7 - WEEKDAY ( [InitialDate], 2 ), 0 )
RETURN
    DATEVALUE ( [InitialDate] ) + _holidayoffset
        + _workDays
        + TIME ( 7, 30, 0 )
        + _remaintime

 10.png

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

You can try to use following calculate column formula to calculate end date based on 'initial date' and 'work hours': 

EndDate =
VAR _todayRemain =
    TIME ( 17, 30, 00 )
        - MAX (
            TIME ( 7, 30, 00 ),
            MIN ( TIME ( 17, 30, 00 ), TIMEVALUE ( [InitialDate] ) )
        )
VAR _totalWorkhours =
    IF (
        WEEKDAY ( [InitialDate], 2 ) <= 5,
        [Work Hours] - _todayRemain,
        [Work Hours]
    )
VAR _workDays =
    IF (
        _totalWorkhours > 0,
        INT ( _totalWorkhours / 10 )
            + IF ( MOD ( _totalWorkhours, 10 ) > 0, 1, 0 ),
        0
    )
VAR _remaintime =
    _totalWorkhours
        - INT ( _totalWorkhours / 10 )
            * _totalWorkhours
VAR _holidayoffset =
    IF ( WEEKDAY ( [InitialDate], 2 ) >= 5, 7 - WEEKDAY ( [InitialDate], 2 ), 0 )
RETURN
    DATEVALUE ( [InitialDate] ) + _holidayoffset
        + _workDays
        + TIME ( 7, 30, 0 )
        + _remaintime

 10.png

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

How can I add 25 hours of working time to that? I tried using the value '25' in space [Work Hours] but didn't work. Also tried Time(25, 00, 00) but none of them made it ok.

 

Example: 28/07/2023 16:23:55 -> 02/08/2023 10:59:55

Any help?

Anonymous
Not applicable

hi @v-shex-msft  Xiaoxin

Thank you, it worked!! excelent answer!

a time ago a wasn't able to reply because of work, but now i appreciate you help!!! 😄 

adambhappy
Resolver II
Resolver II

What is your data source? Is it import or DirectQuery?

Anonymous
Not applicable

is and excel sheet, a column names "FechaInicial" and "TiempoHabil" is given to me to do the calculation

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.