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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Date/Time + Decimal number [number of hours] to get result in Date/Time

Hello,

 

I need to calculate the Starting date and time + period (in hours) to get the result in date/time.

My data setting is following:

 

Starting Date [Date/Time dd:mm:yyyy hh:nn:ssPeriod (Decimal number in hours)End date (Starting date + period)
1.1.202097??

 

I tried to conver the Period in Decimal numbers to Time format, but it doesn't work for higher values.

 

Thanks for help.

 

Petr

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can use the following measure:

 

 

End date =
VAR vday =
    INT ( MAX ( 'Table'[Period] ) / 24 )
VAR vSeconds =
    MOD ( MAX ( 'Table'[Period] ), 24 ) * 3600
VAR vMinutes =
    INT ( vSeconds / 60 )
VAR vRemainingSeconds =
    MOD ( vSeconds, 60 )
VAR vHours =
    INT ( vMinutes / 60 )
VAR vRemainingMinutes =
    MOD ( vMinutes, 60 )
RETURN
    MAX ( 'Table'[Starting Date] ) + vday
        + TIME ( vHours, vRemainingMinutes, vRemainingSeconds )

 

 

Capture5.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

View solution in original post

2 REPLIES 2
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can use the following measure:

 

 

End date =
VAR vday =
    INT ( MAX ( 'Table'[Period] ) / 24 )
VAR vSeconds =
    MOD ( MAX ( 'Table'[Period] ), 24 ) * 3600
VAR vMinutes =
    INT ( vSeconds / 60 )
VAR vRemainingSeconds =
    MOD ( vSeconds, 60 )
VAR vHours =
    INT ( vMinutes / 60 )
VAR vRemainingMinutes =
    MOD ( vMinutes, 60 )
RETURN
    MAX ( 'Table'[Starting Date] ) + vday
        + TIME ( vHours, vRemainingMinutes, vRemainingSeconds )

 

 

Capture5.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

rogletree
Helper III
Helper III

Try something like this:

End date = [Starting Date] + #duration(0, [Period], 0, 0)

https://community.powerbi.com/t5/Desktop/How-to-add-hours-to-DateTime-data/td-p/104443

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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