Convert text to number

sd77000

New Member
Joined
Aug 27, 2009
Messages
47
Hello all,

I am learning how to use Power Query so please be patient. I am creating a query, there is one column that I am unable to convert to a number. The numbers in the column are in text and represent time (hh:mm). When I change the data type to number, decimal or time, receive error in the column. I am unable to find a formula in power query that will convert it. Any help/guidance would be greatly appreciated.

Thanks in advance,
Steve
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If you change the column type of a table (to Time in your case), then textual time representations of time are converted to Time values.

You can try and paste the following code in the Advanced Editor:

Code:
let
    Source = {"01:02","17:58"},
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type time}})
in
    #"Changed Type"

So what are you doing exactly and what error do you get?
Does your data only consists of time representations and nothing else?
 
Upvote 0
Let me better explain, when I convert the column to Time, was before as 1:00, after change, 1:00:00 AM. If the hour is greater than 24 hrs, after the change, Error is displayed where the time was greater than 24 hrs. Sample is shown, with before and after.

Tot HrsTot Hrs
1:001:00:00 AM
0:1512:15:00 AM
60:00Error

<tbody>
</tbody>

Thanks,
Steve
 
Upvote 0
So your data represents durations, not times.

My suggestion is to copy the column, split it in hours and minutes, add a column with the hours and minutes converted to durations which are then converted to decimal values.


Code:
let
    Source = {"01:02","17:58", "60:00"},
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Tot Hrs"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Tot Hrs", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Tot Hrs", "Tot Hrs - Copy"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Duplicated Column", "Tot Hrs - Copy", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Hours", "Minutes"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Hours", Int64.Type}, {"Minutes", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Duration", each Number.From(#duration(0,[Hours],[Minutes],0)), type number),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Hours", "Minutes"})
in
    #"Removed Columns"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,670
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top