Reply
Regular Visitor
Posts: 35
Registered: ‎05-22-2018
Accepted Solution

How to extract numbers before -

I have a column which says the zip codes of the locations out of which few of them have zip-xxxx for the specific block location. When I tried loading it directly it gave me an error. So, when I tried to change the format of the column to text and extract using extract by delimiter "-", its still giving me errors. It's giving me an error message as "[DataFormat.Error] We couldn't convert to Number".


Accepted Solutions
Established Member
Posts: 212
Registered: ‎11-10-2017

Re: How to extract numbers before -

@koganti333,

I could not replicate your issue. It is working fine for me. See the code below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JcrBDYAwDEPRXXKmku3Uhc4Sdf81QOH2vvSrIkkpzlUx7eVWymsPTmWnCGAA/D/DQOvGsz+dFw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Zip Code" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Zip Code", type text}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Text Before Delimiter", each Text.BeforeDelimiter([Zip Code], "-"), type text)
in
    #"Inserted Text Before Delimiter"

View solution in original post


All Replies
Senior Member
Posts: 317
Registered: ‎12-04-2017

Re: How to extract numbers before -

@koganti333,

Did you try converting the column to text in Power Query (Inside Edit Query) and not in the visual area?

 

If not try doing it there and then you can also get the extract by delimiter there.

 

That should fix the issue

Established Member
Posts: 212
Registered: ‎11-10-2017

Re: How to extract numbers before -

@koganti333,

I could not replicate your issue. It is working fine for me. See the code below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JcrBDYAwDEPRXXKmku3Uhc4Sdf81QOH2vvSrIkkpzlUx7eVWymsPTmWnCGAA/D/DQOvGsz+dFw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Zip Code" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Zip Code", type text}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Text Before Delimiter", each Text.BeforeDelimiter([Zip Code], "-"), type text)
in
    #"Inserted Text Before Delimiter"
Regular Visitor
Posts: 35
Registered: ‎05-22-2018

Re: How to extract numbers before -

@Thejeswar

I was doing the editing in the power query editor itself. The extract by delimiter is working only with text columns

Member
Posts: 47
Registered: ‎06-05-2018

Re: How to extract numbers before -

Not sure the error you ran into, I tried this with some dummy data I made. Have you tried using the split column feature? Try that with using - as a delimiter. Alternatively you can use the extract feature and take the first 5 characters. Let me know if that helps.

Regular Visitor
Posts: 35
Registered: ‎05-22-2018

Re: How to extract numbers before -

Thanks @NickNg278 All the time I was transforming the  existing column. Your solution of Adding a new column worked