Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

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"})

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
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

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
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

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

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

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors