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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
sarathD4s
Frequent Visitor

Removing multiple names from a text in a column

I have a column named exception reason which is in text fomat,  within this text there will names of people which will be starting by Mr, Mrs, Miss or Ms, there could be multiple names in a single text,for example Mr A & Mr B or Miss C Mr D.

What i need is to remove the names from the data , so that no personal details are available in the text.

i tried the below  logic , but it didnt remove any of the names. is there any way to resolve this.

 

 

let
// Original text from the column
OriginalText = [Exception Reason],

// List of prefixes to check
Prefixes = {"Miss ", "Mrs ", "Mr ", "Ms "},

// Check if the text starts with any of the prefixes
StartsWithPrefix = List.First(List.Select(Prefixes, each Text.StartsWith(OriginalText, _)), ""),

// Remove the prefix if it exists
RemovePrefix = if StartsWithPrefix <> "" then
let
// Remove the prefix from the text
TextWithoutPrefix = Text.RemoveRange(OriginalText, 0, Text.Length(StartsWithPrefix))
in
Text.Trim(TextWithoutPrefix)
else
OriginalText
in
RemovePrefix

9 REPLIES 9
dufoq3
Super User
Super User

Hi @sarathD4s, this replaces first word between two spasec after defined prefixes.

 

Output

dufoq3_0-1723639085143.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LcyxCsMwDATQXzk85ydKoV2aqaPJIBKVCBzblWVI/j52m02n45737lYtbWQyUwgHCht4nzmbpIhRC/IqQTIoLi2CAu/tZP0/Cu5kK6tERmfKAFZNik+qcXHT4N07ba3j3X7p0brGjKQmEa/ax5d9WaFbT6UDyt/Kpe2mEw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    Prefixes = List.Buffer({"Miss", "Mrs", "Mr", "Ms"}),
    StepBack = Source,
    Ad_Replaced = Table.AddColumn(StepBack, "Replaced", each
        [ a = List.Distinct(List.RemoveItems(List.Combine(List.Transform(Prefixes, (x)=> Text.PositionOf([Column1], x, Occurrence.All))), {-1})), //Prefixes positions
          b = List.Transform(a, (x)=> Text.BetweenDelimiters(Text.Range([Column1], x), " ", " ")),
          c = List.Accumulate(b, [Column1], (state, current)=> Text.Replace(state, current, "*"))
        ][c], type text)
in
    Ad_Replaced

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

This seem sto be ot working , as it create a table and when opened its just repeats the three values that is given in the screen shot, my spreadsheet will have multiple columns and Exception reason is just one of the column and i want to see the anmes removed in  new column next to it

sarathD4s_1-1723828933729.png

Example

Ahmedx
Super User
Super User

you have several names in one line, post an example of several lines to help you

i have created some sample examples on how it will be seen in the below screenshot for your reference

sarathD4s_0-1723828902891.png

 

sarathD4s
Frequent Visitor

Thank you so much for your solution.

I tried the three solutions but i am getting the below errors for the reasons where the names are not available. but it works for the ones with the salutation, but if there are multiplenames it wont be replaces. could you able to help with that

 

sarathD4s_0-1723627189799.png

sarathD4s_1-1723627202970.png

 

sarathD4s_2-1723628223419.png

 

sarathD4s
Frequent Visitor

This is an example of what i am trying to achive, i need to find the names and replace it with a " * " so that names are removed, names will always be starting by Mrs, Miss, mrs, Ms which can help to find the names in the text

sarathD4s_0-1723578690521.png

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Screenshot_2.png

Ahmedx
Super User
Super User

Can you please share your demo input and expected output!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.