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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

DAX Calculated column Measure for DateTime

Hi Experts

 

Here is my Calculated Column Measure 

Hours per Job = (DATEDIFF(FACT_FSM_JOB_DATA[Start Time],FACT_FSM_JOB_DATA[Finish Time],MINUTE)/60)
 
The issue i am having is when the Job finish time is the next day and say 00:04:00 in th morning i am getting (-22.4)hrs which is incorrect if the job start time was 21:49:00...How could i adjust my measure to show the time as positive minutes worked and the correct minutes when we roll over into the next day..
 
See sample data image....
Route111_0-1641303752991.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

If the field Start Date and Finish Date are both in the same day, you can change the formula of your calculated column [Hours per Job] as below if the field Finish Time may span one day to the next day... Please find the details in the attachment.

Note: The part with red font is updated ones.

Hours per Job =
VAR _hours =
    DIVIDE (
        DATEDIFF (
            FACT_FSM_JOB_DATA[Start Time],
            IF (
                'FACT_FSM_JOB_DATA'[Finish Time] < 'FACT_FSM_JOB_DATA'[Start Time],
                'FACT_FSM_JOB_DATA'[Finish Time] + TIME ( 2400 ),
                'FACT_FSM_JOB_DATA'[Finish Time]
            ),
            MINUTE
        ),
        60,
        0
    )
RETURN
    IF (
        'FACT_FSM_JOB_DATA'[Finish Time] < 'FACT_FSM_JOB_DATA'[Start Time],
        _hours + 24,
        _hours
    )

yingyinr_0-1641542157283.png

Otherwise (if the field Start Date and Finish Date span multiple days), please provide more examples and calculation logic as well with screenshot of the final expected result. Thank you.

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

If the field Start Date and Finish Date are both in the same day, you can change the formula of your calculated column [Hours per Job] as below if the field Finish Time may span one day to the next day... Please find the details in the attachment.

Note: The part with red font is updated ones.

Hours per Job =
VAR _hours =
    DIVIDE (
        DATEDIFF (
            FACT_FSM_JOB_DATA[Start Time],
            IF (
                'FACT_FSM_JOB_DATA'[Finish Time] < 'FACT_FSM_JOB_DATA'[Start Time],
                'FACT_FSM_JOB_DATA'[Finish Time] + TIME ( 2400 ),
                'FACT_FSM_JOB_DATA'[Finish Time]
            ),
            MINUTE
        ),
        60,
        0
    )
RETURN
    IF (
        'FACT_FSM_JOB_DATA'[Finish Time] < 'FACT_FSM_JOB_DATA'[Start Time],
        _hours + 24,
        _hours
    )

yingyinr_0-1641542157283.png

Otherwise (if the field Start Date and Finish Date span multiple days), please provide more examples and calculation logic as well with screenshot of the final expected result. Thank you.

Best Regards

Greg_Deckler
Community Champion
Community Champion

@Anonymous Perhaps something like:

Hours per Job = 
  IF(
    [Finish Time] > [Start Time],
    (DATEDIFF(FACT_FSM_JOB_DATA[Start Time],FACT_FSM_JOB_DATA[Finish Time],MINUTE)/60),
    (23/24 + 59/60 + 59/60/60 + 1/24/60/60) - [Start Time] + [Finish Time]
  )

or

  IF(
    [Finish Time] > [Start Time],
    (DATEDIFF(FACT_FSM_JOB_DATA[Start Time],FACT_FSM_JOB_DATA[Finish Time],MINUTE)/60),
    ABS(DATEDIFF(FACT_FSM_JOB_DATA[Start Time]+[StartDate],FACT_FSM_JOB_DATA[Finish Time]+[Finish Date],MINUTE)/60))
  )
  )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors