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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How to calculate time difference for a calculated date/time difference in total hours

Hello,

I did a lot of research and finally ended up with the suitable command i needed... BUT
It doesn´t show me the total hours (26:00:00) as soon it is crossing the date.
So i need to find out the hours between two departure date/times so that i can analyze the duration between... This is required to create some output that helps me to identify required hotelbookings...

 

So what i want to achieve:
Departure 1 = 07/23/2021 12:00:00
Departure 2 = 07/25/2021 08:00:00

= 44:00:00 hours -> (minus the duration of the trip as example 9 hours = 35 hours -> I need a room for two nights

 

HELP.jpg

 

 

I´m so frustrated......
and i just can´t hide it....

I´m about to lose my mind AND I DONT LIKE IT !!! 😛

1 REPLY 1
Anonymous
Not applicable

EVALUATE
var Time1 = date(2021, 7, 23) + 12/24
// Adding a float to a date is like adding
// time to it. For instance, if you want
// to add, say, 10 hours to a date, 
// you add 10/24 since there are 24 hours
// in a day. If you want to add, say, 251
// minutes, you add 251/(24*60) since
// there are 24 * 60 minutes in a day.
// The same patterns continues for any amount
// of time.
var Time2 = date(2021, 7, 24) + 10/24 // add 10 hours
var TimeDiffInDays = 1 * (Time2 - Time1)
var TimeDiffInHours = TimeDiffInDays * 24
return
    SELECTCOLUMNS(
        {(Time1, Time2, TimeDiffInDays, TimeDiffInHours)},
        "Start Date", [Value1],
        "End Date", [Value2],
        "Time Diff In Days", [Value3],
        "Time Diff In Hours", [Value4]
    )

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.