Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Conditionally Value Replacing Based on Another Column Value

 

I’m trying to replace the date in column: [From] conditionally based on the value in column: [#"Resigned / Promoted"], if it is "Yes", the date in column: [From] would be increased by 10 days. I’ve used the below script but it doesn’t work, what is wrong with it?

 

= Table.ReplaceValue(#"Renamed Columns",each[From], each if [#"Resigned / Promoted"] = "Yes" then DateTime.LocalNow()+#duration(10,0,0,0) else [From], Replacer.ReplaceValue,{"From"})

  • I reproduced your scenario and your code worked for me.  But why are you using DateTime.LocalNow() if you are trying to adjust the From value.  Try this instead.

     

    = Table.ReplaceValue(#"Renamed Columns",each[From], each if [#"Resigned / Promoted"] = "Yes" then [From] + #duration(10,0,0,0) else [From], Replacer.ReplaceValue,{"From"})

     

    Pat

     

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    I reproduced your scenario and your code worked for me.  But why are you using DateTime.LocalNow() if you are trying to adjust the From value.  Try this instead.

     

    = Table.ReplaceValue(#"Renamed Columns",each[From], each if [#"Resigned / Promoted"] = "Yes" then [From] + #duration(10,0,0,0) else [From], Replacer.ReplaceValue,{"From"})

     

    Pat

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      You're absolutely right, it works! I've no idea why it wasn't working before, thanks a million.