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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Replace value on column by value of another column and trim the value

Hello,

 

I am trying to copy the values from column 'ref_id' into column 'material'. The ref_id values are of the form 00000000001234-KG, and I want to copy just the number on 'material', so it would be 1234 in this case.

 

imallea_0-1647888462061.png

 

This is what I'm trying and its result. Note that in the image I'm trying to remove leading zeros only. I'm waiting for your answer to add the part to remove what is after "-".

 

Any help?

1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

 

Power Query ~ can be done using Number.FromText

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMkAGJhYmFrre7kqxOnSQiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ref_id = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ref_id", type text}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "material", each Number.FromText(Text.BeforeDelimiter([ref_id], "-")), Int64.Type)
in
    #"Inserted Text Before Delimiter"

 

sevenhills_0-1647913024208.png

Ref: https://docs.microsoft.com/en-us/powerquery-m/number-fromtext 

 

View solution in original post

1 REPLY 1
sevenhills
Super User
Super User

 

Power Query ~ can be done using Number.FromText

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMkAGJhYmFrre7kqxOnSQiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ref_id = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ref_id", type text}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "material", each Number.FromText(Text.BeforeDelimiter([ref_id], "-")), Int64.Type)
in
    #"Inserted Text Before Delimiter"

 

sevenhills_0-1647913024208.png

Ref: https://docs.microsoft.com/en-us/powerquery-m/number-fromtext 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors