Forum Discussion
Convert text to number
- 3 years ago
Hi -
So really, you want to just trim leading zeros from a text value, is that correct?
If so, take a look at this solution:
https://community.powerbi.com/t5/Desktop/Remove-leading-Zero-s-in-Query/m-p/247410
There is a Text.TrimStart function that might do what you want. You didn't post the error you are getting, but I don't believe using "&" to attempt to concatenate a number to a text will work.
Here is an example that seems to do what you want:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgtSS1S0lFySk3OBlIGhkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FirstName = _t, LastName = _t, Hours = _t]),
MyTable = Table.AddColumn(Source,"idbat-HH",each if Text.Contains([Hours],"01") then "VL" & Text.TrimStart([Hours],"0") else null)
in
MyTableCheers,
Peter
Hi -
So really, you want to just trim leading zeros from a text value, is that correct?
If so, take a look at this solution:
https://community.powerbi.com/t5/Desktop/Remove-leading-Zero-s-in-Query/m-p/247410
There is a Text.TrimStart function that might do what you want. You didn't post the error you are getting, but I don't believe using "&" to attempt to concatenate a number to a text will work.
Here is an example that seems to do what you want:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgtSS1S0lFySk3OBlIGhkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FirstName = _t, LastName = _t, Hours = _t]),
MyTable = Table.AddColumn(Source,"idbat-HH",each if Text.Contains([Hours],"01") then "VL" & Text.TrimStart([Hours],"0") else null)
in
MyTable
Cheers,
Peter