Change values within a row with values from a different column

I have attached a snippet of the table. I want to replace the “N” in Rule_Name column with whatever value is in PARAM1 column and Replace the “X” with Param2. In absence of X I just want to replace the “N”. Can anyone help to solve this problem and waht to use?

HI @uix14972

You should be able to do this with a nested string replace.

replace(replace(column("RULE_NAME"),"N", column("PARAM1")), "X" , column("PARAM2"))

1 Like

I’d use a Column Expressions. I like storing the intermediate output as variables because it makes things easier to read:

a = replace(column("RULE_NAME"),"X",column("PARAM2"))
b = replace(a,"N",column("PARAM1"))

1 Like

Thank you…it worked

1 Like

I like the solutions provided above. Just be careful of using “N” without the space since you might get unexpected outcomes. I would use "N ".

1 Like

Thank you it worked.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.