Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Replacing multiple value at once

Is there any way to replace multiple values in a column in just one step? Let's say my column has a, b and c and I want them to be 1 2 and 3. I know I cant create a conditional column but can I make...
  • v-alq-msft's avatar
    5 years ago

    Hi, Anonymous 

     

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

    Table:

     

    You may add a new step with following codes.

    = Table.TransformColumns(#"Changed Type",{"Text",
    each 
    if _="a"
    then 1
    else if _="b"
    then 2
    else if _="c"
    then 3
    else null 
    })

    or

    = Table.ReplaceValue(#"Changed Type",each [Text],each true,
    (x,y,z)=>
    if y="a" then 1
    else if y="b" then 2
    else if y="c" then 3
    else null,
    {"Text"}
    )

     

    Result:

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.