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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
df123445
Helper II
Helper II

substituting null values with another column substring

I have the following raw data:

 

CODEPRODUCT
PRD1engine [AB-PRD1-XY]
PRD2wing [AB-PRD2-WZ]
nulltail [AB-PRD3-TT]
nullwindow[AB-PRD4-AA]

 

as you can see the data is not complete, some rows  have no value in the CODE column, and I need to extract

it from the PRODUCT (But only for the null values) 

 

I guess the pseudo-logic should be:

if CODE=null  

CODE = find occurence of "AB-" in PRODUCT field and grab the following 4 characters   

 

Anyone could help me pu that in M language or point me in the right direction? TIA 

2 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

you can try this

 

= Table.AddColumn(#"Changed Type", "Custom", each if [CODE] ="" then Text.Middle([PRODUCT] ,Text.PositionOf([PRODUCT],"AB-")+3,4) else [CODE])

 

11.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Anonymous
Not applicable

Here is one possible solution for your problem:

cosm_0-1728382041828.png

 


Using
- Text between delimiters
- Conditional column


A tip is to use the functions avaible in the transform pane:

cosm_2-1728382242370.png

 

, in order to specify which text you want to extraxt from the CODE column.

 

Applying the relevant steps automaticcaly generates the following solution code:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCghyMVTSUUrNS8/MS1WIdnTSBYnoRkTGKsXqgKWNgNIxJeWZeekwaSPd8CiINFCqJDEzByZhrBsSApcA6kjJL4fKmOg6OgJlYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CODE = _t, Product = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CODE", type text}, {"Product", type text}}),
    #"Inserted Text Between Delimiters" = Table.AddColumn(#"Changed Type", "Text Between Delimiters", each Text.BetweenDelimiters([Product], "-", "-"), type text),
    #"Code adjusted" = Table.AddColumn(#"Inserted Text Between Delimiters", "Code adjusted", each if [CODE] = "" then [Text Between Delimiters] else [CODE]),
    #"Removed Columns" = Table.RemoveColumns(#"Code adjusted",{"Text Between Delimiters"})

in
    #"Removed Columns"

 



Kind regards

Mark as a solution if the answer solved your question 🙂

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Here is one possible solution for your problem:

cosm_0-1728382041828.png

 


Using
- Text between delimiters
- Conditional column


A tip is to use the functions avaible in the transform pane:

cosm_2-1728382242370.png

 

, in order to specify which text you want to extraxt from the CODE column.

 

Applying the relevant steps automaticcaly generates the following solution code:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCghyMVTSUUrNS8/MS1WIdnTSBYnoRkTGKsXqgKWNgNIxJeWZeekwaSPd8CiINFCqJDEzByZhrBsSApcA6kjJL4fKmOg6OgJlYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CODE = _t, Product = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CODE", type text}, {"Product", type text}}),
    #"Inserted Text Between Delimiters" = Table.AddColumn(#"Changed Type", "Text Between Delimiters", each Text.BetweenDelimiters([Product], "-", "-"), type text),
    #"Code adjusted" = Table.AddColumn(#"Inserted Text Between Delimiters", "Code adjusted", each if [CODE] = "" then [Text Between Delimiters] else [CODE]),
    #"Removed Columns" = Table.RemoveColumns(#"Code adjusted",{"Text Between Delimiters"})

in
    #"Removed Columns"

 



Kind regards

Mark as a solution if the answer solved your question 🙂

ryan_mayu
Super User
Super User

you can try this

 

= Table.AddColumn(#"Changed Type", "Custom", each if [CODE] ="" then Text.Middle([PRODUCT] ,Text.PositionOf([PRODUCT],"AB-")+3,4) else [CODE])

 

11.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




thanks youuuuu!!!!!

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors