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
Blues88
Helper I
Helper I

Time format m:ss to hh:mm:ss

Hello,

 

I have start-time data that looks like the below "Current" column and I need to transform it into the "Desired Result" column:

 

Current          Desired Result

124                12:01:24 AM

3440              12:34:40 AM

33218            03:32:18 AM

232427          11:24:27 PM

 

Additionally, using the "Units Loaded" column (not shown above) I need to show units loaded per hour/day/month, etc. Each row has a "Units Loaded" value along with the time data from above. 

 

End Result Visual:

 

Blues88_2-1631302531555.png

 

 

How can I achieve this?

1 ACCEPTED SOLUTION
watkinnc
Super User
Super User

Sorry!  I actually had to go to my desk to get it right.  Code below:

 

let
Source = {124, 3440, 33218, 232427},
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Current"}}),
#"Changed Type" = Table.TransformColumns(#"Renamed Columns",{{"Current", Text.From}}),
#"Split Column by Position" = Table.SplitColumn(#"Changed Type", "Current", Splitter.SplitTextByPositions({0, 2}, true), {"Current.1", "Seconds"}),
#"Split Column by Position1" = Table.SplitColumn(#"Split Column by Position", "Current.1", Splitter.SplitTextByPositions({0, 2}, true), {"Hours", "Minutes"}),
#"Replaced Value" = Table.ReplaceValue(#"Split Column by Position1","","0",Replacer.ReplaceValue,{"Hours", "Minutes", "Seconds"}),
#"Changed Type1" = Table.TransformColumns(#"Replaced Value",{{"Hours", Number.From}, {"Minutes", Number.From}, {"Seconds", Number.From}}),
#"Added Custom" = Table.AddColumn(#"Changed Type1", "Time", each #time([Hours], [Minutes], [Seconds]), type time)
in
#"Added Custom"

 

watkinnc_0-1631544222472.png

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

6 REPLIES 6
watkinnc
Super User
Super User

Sorry!  I actually had to go to my desk to get it right.  Code below:

 

let
Source = {124, 3440, 33218, 232427},
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Current"}}),
#"Changed Type" = Table.TransformColumns(#"Renamed Columns",{{"Current", Text.From}}),
#"Split Column by Position" = Table.SplitColumn(#"Changed Type", "Current", Splitter.SplitTextByPositions({0, 2}, true), {"Current.1", "Seconds"}),
#"Split Column by Position1" = Table.SplitColumn(#"Split Column by Position", "Current.1", Splitter.SplitTextByPositions({0, 2}, true), {"Hours", "Minutes"}),
#"Replaced Value" = Table.ReplaceValue(#"Split Column by Position1","","0",Replacer.ReplaceValue,{"Hours", "Minutes", "Seconds"}),
#"Changed Type1" = Table.TransformColumns(#"Replaced Value",{{"Hours", Number.From}, {"Minutes", Number.From}, {"Seconds", Number.From}}),
#"Added Custom" = Table.AddColumn(#"Changed Type1", "Time", each #time([Hours], [Minutes], [Seconds]), type time)
in
#"Added Custom"

 

watkinnc_0-1631544222472.png

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
watkinnc
Super User
Super User

Are you first changing these to text values before splitting?


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
Blues88
Helper I
Helper I

I wasn't able to get either of these solutions to work. Could be an error on my end. 

 

However, I solved by adding a custom column in M that added leading zeroes to all numbers to make it a string of 6 and then used this formula to add a new column in DAX:

 

= (LEFT(TIMELOG[Add Zeroes],2)+(MID(TIMELOG[Add Zeroes],3,2)/60)+(RIGHT(TIMELOG[Add Zeroes],2)/3600))/24
 
It worked.
 
Blues88_0-1631541708138.png

 

 

I appreciate your replies. Have a great day!
mahoneypat
Employee
Employee

You could also use a DAX column expression like this to get the column to be used on your X axis.  Replace Times[Current] with your actual Table[Column].

 

mahoneypat_0-1631310457929.png

 

NewColumn = var thisnumber = Times[Current]
var rounded = MROUND(thisnumber, 10000)
return FORMAT(rounded, "#0:00:00")
 
Pat
 

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


watkinnc
Super User
Super User

First, change the number column to text, then split the column like this.: 

 

=Table.SplitColumn(TableName, "Current", 

Splitter.SplitTextByRepeatedLengths(2, true), {"Hours", "Minutes", "Seconds"}))

 

-Note, I'm not sure what order they will come out as, cause I'm outside, but you can rename as needed.

 

Make sure that you change the new columns back to numbers, then it's just:

 

Table.AddColumn(PriorStepName, "Time", each #time([Hour], [Minutes], [Seconds]))

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

I tried to create a custom column and all the data came out as an error. See below.

 

Blues88_1-1631540124261.png

 

 

Blues88_0-1631540072556.png

 

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.

Top Solution Authors