Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Conditional Replace Using Outside table

Hello, I'm trying to replace some text using an outside table. The original data looks like this: Criteria Thing 1, Thing 2, Thing 3 Thing 2, Thing 5, Thing 1 The Replacement tabl...
  • v-dineshya's avatar
    v-dineshya
    1 year ago

    Hi Anonymous ,

     

    Table.AddColumn(
    #"Added Criteria Column",
    "List Replace",
    (x) =>
    let
    match = Table.SelectRows(
    #"Conditional Replacement",
    (r) => Text.Contains(x[Criteria], r[Criteria1]) and Text.Contains(x[Criteria], r[Criteria2])
    ),
    result = if not Table.IsEmpty(match) then
    let
    items = Text.Split(x[Criteria], ", "),
    filtered = List.RemoveItems(items, {match{0}[Criteria1], match{0}[Criteria2]}),
    updated = List.InsertRange(filtered, 0, {match{0}[Replace]}),
    combined = Text.Combine(updated, ", ")
    in
    combined
    else
    x[Criteria]
    in
    result
    )

     

    If my response has resolved your query, please mark it as the Accepted Solution to assist others. Additionally, a 'Kudos' would be appreciated if you found my response helpful.

    Thank you