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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Brij
Helper III
Helper III

How to add hours to datatime based on a condition in Power Query?

Hi,

 

I need some help in adding a new DateTime column based on a condition on an existing DateTime column.

 

Requirement:

Brij_0-1658888926365.png

 

 

Thank you,

Brijesh

4 REPLIES 4
VahidDM
Super User
Super User

Hi @Brij 

Update: Oh you need PQ solution, sorry missed that part

Try this DAX code to add a calculated column to your table:

 

Final Output =
VAR _Time =
    TIMEVALUE ( 'Table'[Date Time] )
VAR _Date =
    DATEVALUE ( 'Table'[Date Time] )
VAR _5_PM =
    TIME ( 17, 00, 00 )
VAR _9_AM =
    TIME ( 9, 0, 0 )
RETURN
    IF ( _Time > _5_PM, _Date + 1 + _9_AM, 'Table'[Date Time] )

 

Output:

VahidDM_0-1658891910189.png

 



 

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

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

Thanks Vahid,

Actually, I was looking for this solution in Power Query as I need to convert this output column data type to 'Date' to be able to make the relationship with DimDate table in the model. Are you able to help in Power BI? 

Hi @Brij 

 

Try this DAX to change the output to the Date, and use that for relationship (make sure the format is Date for that column)

Final Output =
VAR _Time =
    TIMEVALUE ( 'Table'[Date Time] )
VAR _Date =
    DATEVALUE ( 'Table'[Date Time] )
VAR _5_PM =
    TIME ( 17, 00, 00 )
VAR _9_AM =
    TIME ( 9, 0, 0 )
Var _Out = 
    IF ( _Time > _5_PM, _Date + 1 + _9_AM, 'Table'[Date Time] )
return
    DATEVALUE ( _Out )

 

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

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

 

Hi @VahidDM 

Thank you again for the effort.

This looks good. However, one thing I have noticed with this solution is that if a 'start_date_time' is on Friday after 5 PM then it is returning Saturday's date with 9 AM time! Is it possible if it checks for the weekend and return the following Monday date? 

Thank you

Brijesh 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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