Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

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".

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous,

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

5 REPLIES 5
BKirsch12
Resolver II
Resolver II

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.

Anonymous
Not applicable

@Anonymous,

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

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

Thejeswar
Super User
Super User

@Anonymous,

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

Anonymous
Not applicable

@Thejeswar

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.