Forum Discussion

rgu101's avatar
rgu101
Helper I
2 years ago
Solved

Replace flexible text

Hello,   I'm creating a comments dashboard from survey data and I need to remove all names, phone numbers, and emails but I'm unsure on how to mass remove these variables from the text without manu...
  • marcelsmaglhaes's avatar
    marcelsmaglhaes
    2 years ago

    Hey rgu101 ,

    If you have a pattern like "My name is [text1] [text2]", you can remove that string. The problem is that if you have something like "My name is Josh and I love cars", the extraction will consider removing "My name is Josh and" because the default is to remove the next 2 words after My name is. 

    And like you said, you're going to assume that the next two words are going to be first and last name. If you don't set a standard, it's kind of impossible to get the job done.

    You should start with something like that.

    let
    RemoveNameStep = Table.TransformColumns(
    YourPreviousStep,
    {"Column_Name", each
    let
    text = Text.From(_),
    nameIsPosition = Text.PositionOf(text, "My name is"),
    result =
    if nameIsPosition >= 0 then
    let
    textWithoutName = Text.Start(text, nameIsPosition)
    in
    textWithoutName
    else text
    in
    result
    }
    )

    Please note that this code is a partial solution and may need further work to completely remove the desired data. The structure of Power Query can make text manipulation complex in certain cases. 
    Regards,
    Marcel