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! Learn more

Reply
TheOriginalDeeb
Frequent Visitor

Replace Last Character from Every Word in a List

I started working on a solution for a problem a while back but then I put it on the back-burner until now. For background purposes, see: http://community.powerbi.com/t5/Desktop/Find-amp-Count-Matching-Words-in-Lists/m-p/378251

 

The basic problem is that I'm trying to compare 2 columns of a table to see how many words match. I got a lot of help with the M code (thanks everybody) and it works..... almost. The problem is that theres no way to match plural words (specifically words ending in 's') to singular.

 

Ex. Column 1 = "Original Phrase" / Column 2 = "Words to Match"

If the "Original Phrase" = 'workout shirt for men' & "Words to Match" = 'men workout shirt' then there's a 100% match (All Good!). But it screws up if with one column has all or partial plurals --- 'workout shirt for men' will not match any for 'mens workouts shirts'

 

So I'm thinking that a workaround is to create some conditional logic to to kinda stem all plural words in each column.

 

I need some code that evaluates each word in both lists and for each word ending in 's', remove that 's'

 

I've been fiddling with .Text.EndsWith but can't get the logic working to remove or replace the 's'

 

Any help would be gladly appreciated. Thanks!!!

 

 

 

1 ACCEPTED SOLUTION

Hi @TheOriginalDeeb

Use Text.TrimEnd instead of Text.Trim in code above.

9.png

10.png

 

Best Regards

Maggie

View solution in original post

6 REPLIES 6
v-juanli-msft
Community Support
Community Support

Hi @TheOriginalDeeb

Test with this simple data in Power Query

4.png

 

M code in advanced editor

let

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKs8vys4vLVEozsgsKlFIyy9SyE3NU9JRApLFClDJYohssVKsTrRSemqJQmV+aZFCen5iDlAhkF+MEACqiQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [list1 = _t, list2 = _t]),

    #"Changed Type" = Table.TransformColumnTypes(Source,{{"list1", type text}, {"list2", type text}}),

    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "list2", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"list2.1", "list2.2", "list2.3"}),

    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"list2.1", type text}, {"list2.2", type text}, {"list2.3", type text}}),

    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Text.Trim([list2.1],"s")),

    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Text.Trim([list2.2],"s")),

    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each Text.Trim([list2.3],"s")),

    #"Merged Columns" = Table.CombineColumns(#"Added Custom2",{"Custom", "Custom.1", "Custom.2"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),

    #"Removed Columns" = Table.RemoveColumns(#"Merged Columns",{"list2.3", "list2.2", "list2.1"})

in

#"Removed Columns"

 

final output

5.png

 

Best Regards

Maggie

Thanks so much Maggie for your help.

 

Unfortunately your solution does not work 100%.

 

It removes the beginning 'S' on some words, which is not desired.

 

But thanks again!

Hi @TheOriginalDeeb

Use Text.TrimEnd instead of Text.Trim in code above.

9.png

10.png

 

Best Regards

Maggie

Maggie,

 

How do I change the Source (1st step)? I have no idea what you are doing with the source.

 

I want to be able to connect to a table inside Power BI (without JSON).

 

Thanks!

TheOriginalDeeb
Frequent Visitor

Edited the title to make it clearer about the problem that I'm hoping to solve.

TheOriginalDeeb
Frequent Visitor

By the way, I'm open to a DAX solution. But I'd prefer M Code.

 

Thanks!

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