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

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

Top Solution Authors
Top Kudoed Authors