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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Kebas_Leech
Helper I
Helper I

M Language removing text based on mulitple columns

Hello,

 

Based on a condition that a column [Name] contains text "Jonh" i need it to do the following: 

Check which words of column [Info] and [Extrainfo] are contained in column [Prod] and remove them.

 

[Prod][Info][Extrainfo]Result
House Made Of WoodMadeOf WoodHouse

 

Any Help? Cant make it work for two columns 

Thanks

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Kebas_Leech 

 

Download example PBIX file

 

This code will do it.  I assume the name is meant to be John, rather than Jonh.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFPSUfLILy1OVfBNTElV8E9TCM/PTwEKgrhACiYQGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Prod = _t, Info = _t, Extrainfo = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Result", each if [Name] = "John" then Text.Combine(List.RemoveItems(Text.Split([Prod], " "), Text.Split([Info] & " " & [Extrainfo], " ")), " ") else "0")
in
    #"Added Custom"

 

 

hse2.png

 

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

2 REPLIES 2
slorin
Super User
Super User

Hi

Add new column

if [Name]="Jonh" then Replacer.ReplaceText(Replacer.ReplaceText([Prod],[Extrainfo],""),[Info],"") else [Prod]

Stéphane 

PhilipTreacy
Super User
Super User

Hi @Kebas_Leech 

 

Download example PBIX file

 

This code will do it.  I assume the name is meant to be John, rather than Jonh.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFPSUfLILy1OVfBNTElV8E9TCM/PTwEKgrhACiYQGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Prod = _t, Info = _t, Extrainfo = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Result", each if [Name] = "John" then Text.Combine(List.RemoveItems(Text.Split([Prod], " "), Text.Split([Info] & " " & [Extrainfo], " ")), " ") else "0")
in
    #"Added Custom"

 

 

hse2.png

 

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors