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
Anonymous
Not applicable

Can not convert to number

Hi,

 

I have a problem with a column in power query editor where I can not convert some rows to a number. For example I have:

 

Product code

49204832

39405932

43940392

59104323

58371946

EP395821

EP398190

 

I made this whole column text because I would get an error if it was a number. But now I made this whole column a text column I still get errors where they say: Can not convert EP398190 to a number.

 

Can someone help me with this problem?

1 ACCEPTED SOLUTION
v-xuding-msft
Community Support
Community Support

Hi @Anonymous 

 

By my test, we can not convert "EP395821" to a number directly. There are two ways to  try.

 

  1. Add column with Test.Remove() functions to  separate numbers and letters , then convert text to number.

Choose Add Column --> Custom Column

Capture2.PNGCapture3.PNG

Check the result in Advanced Editor:

 

let

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PcexEYBACATAXogNgAPlCjA3Z+i/DUffcbPtlqBrFFxmawFDk1/iGbiSNA04VgqHMfY35wVmuf0po8rMDQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Product code" = _t]),

    #"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Remove([Product code], {"A".."Z"})),

    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}})

in

#"Changed Type"

 

       2.Use Split Column option and IF function to separate numbers and letters , then convert text to number.

 

 ​Firstly, choose Home --> Split Column --> By Non-Digit to Digit

Capture4.PNG

Secondly, choose  Add Column --> Custom Column 

Capture1.PNGCapture5.PNG



Check the result in Advanced Editor:

 

let

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PcexEYBACATAXogNgAPlCjA3Z+i/DUffcbPtlqBrFFxmawFDk1/iGbiSNA04VgqHMfY35wVmuf0po8rMDQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Product code" = _t]),

    #"Split Column by Character Transition" = Table.SplitColumn(Source, "Product code", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Product code.1", "Product code.2"}),

    #"Added Custom" = Table.AddColumn(#"Split Column by Character Transition", "Custom", each if [Product code.2] = null then [Product code.1] else [Product code.2]),

    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}})

in

#"Changed Type"

 

 

Best Regards,

Xue Ding

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-xuding-msft
Community Support
Community Support

Hi @Anonymous 

 

By my test, we can not convert "EP395821" to a number directly. There are two ways to  try.

 

  1. Add column with Test.Remove() functions to  separate numbers and letters , then convert text to number.

Choose Add Column --> Custom Column

Capture2.PNGCapture3.PNG

Check the result in Advanced Editor:

 

let

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PcexEYBACATAXogNgAPlCjA3Z+i/DUffcbPtlqBrFFxmawFDk1/iGbiSNA04VgqHMfY35wVmuf0po8rMDQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Product code" = _t]),

    #"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Remove([Product code], {"A".."Z"})),

    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}})

in

#"Changed Type"

 

       2.Use Split Column option and IF function to separate numbers and letters , then convert text to number.

 

 ​Firstly, choose Home --> Split Column --> By Non-Digit to Digit

Capture4.PNG

Secondly, choose  Add Column --> Custom Column 

Capture1.PNGCapture5.PNG



Check the result in Advanced Editor:

 

let

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PcexEYBACATAXogNgAPlCjA3Z+i/DUffcbPtlqBrFFxmawFDk1/iGbiSNA04VgqHMfY35wVmuf0po8rMDQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Product code" = _t]),

    #"Split Column by Character Transition" = Table.SplitColumn(Source, "Product code", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Product code.1", "Product code.2"}),

    #"Added Custom" = Table.AddColumn(#"Split Column by Character Transition", "Custom", each if [Product code.2] = null then [Product code.1] else [Product code.2]),

    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}})

in

#"Changed Type"

 

 

Best Regards,

Xue Ding

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.