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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher 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
Community Champion
Community Champion

@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: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

View solution in original post

1 REPLY 1
smpa01
Community Champion
Community Champion

@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: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.