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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Mediviz
Frequent Visitor

how to calculate the time between two entries that are between two times (21:00:00 - 05:00:00)

Hello everyone,

 

I would like your urgent help.

I would like to calculate the time of night work (21:00:00 - 05:00:00) between entry (date & time Start) and (date & time End) located.
example:

 

Date & time start

                              date & time end

Time between 21:00:00 and 05:00:00

10/02/2023 16:00:00

                            10/02/2023 23:00:00

02:00:00

11/02/2023 23:00:00

                            12/02/2023 08:00:00

06:00:00

15/02/2023 14:00:00

                            15/02/2023 23:30:00

02:30:00

thank you in advance for your help.

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@Mediviz  you can do something like this

 

Measure = 
VAR __start =
    MAX ( 'Table'[Date & time start] )
VAR __end =
    MAX ( 'Table'[Date & time end] )
VAR hardStart =
    DATEVALUE ( __start ) + TIME ( 21, 00, 00 )
VAR modStart =
    IF ( hardStart > __start, hardStart, __start )
VAR hardEnd =
    DATEVALUE ( __start ) + 1 // since night shift, the end date will always flow +1 from start
        + TIME ( 05, 00, 00 )
VAR modEnd =
    IF ( hardEnd < __end, hardEnd, __end )
RETURN
    modEnd - modStart

 

 

smpa01_0-1676309586257.png

PFA

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

1 REPLY 1
smpa01
Super User
Super User

@Mediviz  you can do something like this

 

Measure = 
VAR __start =
    MAX ( 'Table'[Date & time start] )
VAR __end =
    MAX ( 'Table'[Date & time end] )
VAR hardStart =
    DATEVALUE ( __start ) + TIME ( 21, 00, 00 )
VAR modStart =
    IF ( hardStart > __start, hardStart, __start )
VAR hardEnd =
    DATEVALUE ( __start ) + 1 // since night shift, the end date will always flow +1 from start
        + TIME ( 05, 00, 00 )
VAR modEnd =
    IF ( hardEnd < __end, hardEnd, __end )
RETURN
    modEnd - modStart

 

 

smpa01_0-1676309586257.png

PFA

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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