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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
rocky09
Solution Sage
Solution Sage

Calculating Working hours

I have this following Data, I am trying to find a way to calculating  Working hours in betwen dates excluding Weekends.

Works hours are between: Morning 9:00 AM to Evening 6:00 PM and Saturday and Sunday are holidays.

 

TicketIDACTIVITY_DATE       LASTMODIFIEDDATE    
8625628-12-2017 03:1128-12-2017 15:11
8989015-08-2017 20:2315-08-2017 21:12
11161104-10-2017 21:3010-10-2017 13:00
11151104-10-2017 02:3010-10-2017 13:00
11154204-10-2017 02:4110-10-2017 13:00
11148504-10-2017 02:4110-10-2017 13:00
21141106-10-2017 14:2510-10-2017 13:00
15089510-11-2017 12:3218-01-2018 13:29
15299608-08-2017 03:4009-08-2017 11:00

 

any help?

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

HI @rocky09,

 

You can try to use below calculated column formula to calculate valid working hour:

 

Work Hour = 
VAR filtered =
    FILTER (
        ADDCOLUMNS (
            CROSSJOIN (
                CALENDAR ( [ACTIVITY_DATE], [LASTMODIFIEDDATE] ),
                SELECTCOLUMNS ( GENERATESERIES ( 9, 18 ), "Hour", [Value] )
            ),
            "Day of week", WEEKDAY ( [Date], 2 )
        ),
        [Day of week] < 6
            && [TicketID] = EARLIER ( Table1[TicketID] )
    )
VAR hourcount =
    COUNTROWS (
        FILTER (
            filtered,
            (
                [Date] >= DATEVALUE ( [ACTIVITY_DATE] )
                    && [Hour]
                        > HOUR ( [ACTIVITY_DATE] ) + 1
            )
                && (
                    [Date] <= DATEVALUE ( [LASTMODIFIEDDATE] )
                        && [Hour]
                            > HOUR ( [LASTMODIFIEDDATE] ) - 1
                )
        )
    )
VAR remained =
    DATEDIFF (
        TIMEVALUE ( [ACTIVITY_DATE] ),
        TIME ( HOUR ( [ACTIVITY_DATE] ) + 1, 0, 0 ),
        MINUTE
    )
        + DATEDIFF (
            TIME ( HOUR ( [LASTMODIFIEDDATE] ) - 1, 0, 0 ),
            TIMEVALUE ( [LASTMODIFIEDDATE] ),
            MINUTE
        )
RETURN
    IF ( hourcount <> BLANK (), (hourcount*60 + remained)/60, 0 )

 2.PNG

 

Regards,

Xiaoxin Sheng

View solution in original post

34 REPLIES 34
Anonymous
Not applicable

I tried this solution for the data in SQL server database. I am also getting the same error:

 

"An argument of function 'TIME' has the wrong data type or the result is too large or too small."

 

Can some one please help me to replve this 

KKMUrthy

Working Hours.jpg

Please check your Data Type for the Date Column. It should be Date format.

Anonymous
Not applicable

I ensure the data type as Datetime in query editor. I then changed the datetime format to the one shown in the screenshot

Anonymous
Not applicable

I chose  the data type as Datetime for the date fields  in query editor. I then changed the datetime format to the one shown in the screenshot in the data tab. I still get the same error

any thoughts please?

 

replace the comma with a semicolon

 

Cattura.png

Anonymous
Not applicable

Hi

Thank you for spending time on this issue.

I am getting the syntax error: The syntax for ';' is incorrect.

for using ; in place of ,

I am using the power BI Desktop( Aug 2018)

Any further help is greatly appreciated

Did you checked your data type of Date Column in query editor?

@Anonymous

 

Thank you so much sir.

 

I am getting the below error.

 

The Start date in Calendar function can not be later thanthe end date.

 

I guess, the first column may have greater date than modified date. Is there a way to dealth it

Anonymous
Not applicable

Hi @rocky09,

 

>>I guess, the first column may have greater date than modified date. Is there a way to dealth it

It means your table contains records which start date greater than end date. Datediff function not support calculated with records who have greater startdate(compare with end date).

 

You can add some conditions to ignore calculation when 'start date' greater than 'end date'.

 

Notice: DATEDIFF(start date, end date, unit)

 

Regards,

Xiaoxin Sheng

Hi @Anonymous I got a question for you:

 

I have 2 issues when I use your solution.

 

1. Error because those fields in calendar can not be blank.

2. Error because sometimes the lastdate is previous to firstdate.

 

Can you PLEASE give me some solution? I know those are conditions I have to add in the same code you put. But I don't know where to make it work.

 

Thanks man! I hope you to be fine.

 

Hi, 

 

I tried the formula above and I get the error message "The start date or end date in Calendar function can not be Blank value". Any way to resolve this?

 

Thanks

actually, i found the reason,

 

My Date is changing once loading to data model. Actually, the time is early monring. Is it possible to prevent?

example: from 01-12-2017 01:50 to 01-12-2017 PM 01:50

I got the same error, could you solve it ?

rocky09
Solution Sage
Solution Sage

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.