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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors