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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Turning hour as number into time

Hello

 

I have data where the hours are numbered 1-24 and stored as whole numbers

 

I would like to convert these to actual times s0 00:00, 01:00, 02:00 etc  and then add them to my date column to create a datetime.

 

I;ve tried used #duration and subtracting -1 from Hour but I get 00:00 as the time for every hour, regardless of which one it was originally.

 

 

Where am I going wrong?

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

Without your code it is hard to say where you went wrong.

 

This is working code:

 

let
    Source = Table.FromColumns({{1..24},List.Dates(#date(2017,6,9),24,#duration(1,0,0,0))},type table[hours = Int64.Type, date = date]),
    #"Added Custom" = Table.AddColumn(Source, "time", each #time(0,0,0)+#duration(0,[hours]-1,0,0)),
    #"Inserted Merged Date and Time" = Table.AddColumn(#"Added Custom", "datetime", each [date] & [time], type datetime)
in
    #"Inserted Merged Date and Time"
Specializing in Power Query Formula Language (M)

View solution in original post

1 REPLY 1
MarcelBeug
Community Champion
Community Champion

Without your code it is hard to say where you went wrong.

 

This is working code:

 

let
    Source = Table.FromColumns({{1..24},List.Dates(#date(2017,6,9),24,#duration(1,0,0,0))},type table[hours = Int64.Type, date = date]),
    #"Added Custom" = Table.AddColumn(Source, "time", each #time(0,0,0)+#duration(0,[hours]-1,0,0)),
    #"Inserted Merged Date and Time" = Table.AddColumn(#"Added Custom", "datetime", each [date] & [time], type datetime)
in
    #"Inserted Merged Date and Time"
Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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