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

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

Reply

Convert Data Type to time or Duration

Hello , 

 

I have a time period that I need to covernt in to a time period on PowerBI, but it gives me a error, I tried sever ways did not work. I am kinda stumped. I would really appreciate if anybody tell me what wrong.  

 

Data

LocationTime PeriodTraffic% Traffic
100 - Park City7:00 AM - 7:59AM30.024
100 - Park City8:00 AM - 8:59AM30.024
100 - Park City9:00 AM - 9:59AM20.016
100 - Park City10:00 AM - 10:59AM80.063
100 - Park City11:00 AM - 11:59AM100.079
100 - Park City12:00 PM - 12:59PM120.094
100 - Park City1:00 PM - 1:59PM140.11
100 - Park City2:00 PM - 2:59PM120.094

 

When I convert it, gives me below error

Convert.PNG

Error.PNG

 

Thank you So mcuh

DHana 

1 ACCEPTED SOLUTION

DHana, please understand that a time value is 1 timestamp; if converted to a number then it will be between 0 and 1.

A Time Period like yours is just text.

 

Having said that, in the Query Editor: Add Column - Extract - Text Before Delimiter: delimiter <space>, advanced, skip 1.

Rename the column to Start Time and adjust the data type to Time.

 

Close & Load. In the Data view, tab Modeling, select Time Period and sort by Column Start Time.

 

Generated query code (the first 2 steps just create the table):

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc+9CsMwDATgVzGe06JzfmxlC5kD3kOGjKVb6dK3r2on9hJBB4E4+DhpXS2IzM3E/fU08+P9sY31o0TTIqkfe54WiVoZupPr7NZckVBI+JdwIXwSlwkGhYCKkfVAIaOh1RAqwolAWXnWlPupmJQTFZM6DmTtJ1RUTJcMoJDac1mzfQE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Location = _t, #"Time Period" = _t, Traffic = _t, #"% Traffic" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Time Period", type text}, {"Traffic", Int64.Type}, {"% Traffic", type number}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Start Time", each Text.BeforeDelimiter([Time Period], " ", 1), type text),
    #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Text Before Delimiter",{{"Start Time", type time}})
in
    #"Changed Type1"

 

 

Sort Time Period by Start Time.pngGraph % Traffic by Time Period.png

Specializing in Power Query Formula Language (M)

View solution in original post

6 REPLIES 6
Vvelarde
Community Champion
Community Champion

@dananjayaprasad

 

HI, Dhana:

 

Please follow the steps :

 

Duration.gif

 

Regards

 

Victor

Lima  - Peru

 

 




Lima - Peru

Hey Victor, 

 

Thank you so much for clear instructions. I learn new thing too, but I think I counfused you a bit. please see below image. My time period does not recognize as time. Capture.PNG

 

You can see this picture, my time period take it as a General Number. Its should be sort as 7. AM to PM, but it is not. I try to convert the colounm as time. Doest not work. 

 

I would really appreciate your time. 

 

Thank you 

Dhana

@dananjayaprasad

 

You need to specify the sort of the interval times.

 

You can find a sample in this thread:

 

https://community.powerbi.com/t5/Desktop/Sorting-by-Month-as-Text-Jan-Feb-Mar-etc/td-p/9237

 

Regards

 

Victor

Lima - Peru




Lima - Peru

Hey Vector, 

 

Now I got a new problem. Do you know by any chance. how to concatenate two time? I used two column, it gives me a error. I want something like this 7.00.00 AM - 7.59.00 AM. ( Sorry, I could not figure it out the time intervel) 

 

Capture.PNG

 

Thank you so much

Dhana 

DHana, please understand that a time value is 1 timestamp; if converted to a number then it will be between 0 and 1.

A Time Period like yours is just text.

 

Having said that, in the Query Editor: Add Column - Extract - Text Before Delimiter: delimiter <space>, advanced, skip 1.

Rename the column to Start Time and adjust the data type to Time.

 

Close & Load. In the Data view, tab Modeling, select Time Period and sort by Column Start Time.

 

Generated query code (the first 2 steps just create the table):

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc+9CsMwDATgVzGe06JzfmxlC5kD3kOGjKVb6dK3r2on9hJBB4E4+DhpXS2IzM3E/fU08+P9sY31o0TTIqkfe54WiVoZupPr7NZckVBI+JdwIXwSlwkGhYCKkfVAIaOh1RAqwolAWXnWlPupmJQTFZM6DmTtJ1RUTJcMoJDac1mzfQE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Location = _t, #"Time Period" = _t, Traffic = _t, #"% Traffic" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Time Period", type text}, {"Traffic", Int64.Type}, {"% Traffic", type number}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Start Time", each Text.BeforeDelimiter([Time Period], " ", 1), type text),
    #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Text Before Delimiter",{{"Start Time", type time}})
in
    #"Changed Type1"

 

 

Sort Time Period by Start Time.pngGraph % Traffic by Time Period.png

Specializing in Power Query Formula Language (M)

Thank you So much. This works. I appreciate your time and help. 

Helpful resources

Announcements
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 Kudoed Authors