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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DanielCooper
Regular Visitor

Conditional replace text based on if the value is present in another column in the same row

Hi,

 

I'm having trouble using the Table.ReplaceValue function with a condition. 

 

I want to replace the values in one field (Print), with the values in another field (REPLACE Print), but only if the value on that row in the 'REPLACE Print' field is there. 

 

For example I have a lot of rows where I have a value in the 'Print' column which needs to be replaced with the new value in the 'REPLACE Print' column. But also some null rows in the 'Print' column which need to be replaced with the value in 'REPLACE Print' column.

 

Can anyone advise how I fix this formula, I want to minimise adding helper columns and instead do the whole task in the one step.

 

#"Replaced print" = Table.ReplaceValue(#"Replaced end use", each [Print], each if [REPLACE Print] = null then [Print] else [REPLACE Print], Replacer.ReplaceText,{"Print"})

 

Many thanks in advanced!

 

Best,

 

Dan

 

DanielCooper_0-1667516700673.png

 

 

1 ACCEPTED SOLUTION
jennratten
Super User
Super User

Hello!  Please give this a try...

= Table.ReplaceValue(#"Previous Step Name", each [Print], each [REPLACE Print] ?? [Print], Replacer.ReplaceValue,{"Print"})

This statement says exactly what you are trying to do.  The other difference between it and your script is that you had the replacer function as Replacer.ReplaceText (partial value) instead of Replacer.ReplaceValue (entire value).

BEFORE:

jennratten_0-1667517157293.png

 

AFTER:

jennratten_1-1667517180374.png

 

View solution in original post

3 REPLIES 3
jennratten
Super User
Super User

Hello!  Please give this a try...

= Table.ReplaceValue(#"Previous Step Name", each [Print], each [REPLACE Print] ?? [Print], Replacer.ReplaceValue,{"Print"})

This statement says exactly what you are trying to do.  The other difference between it and your script is that you had the replacer function as Replacer.ReplaceText (partial value) instead of Replacer.ReplaceValue (entire value).

BEFORE:

jennratten_0-1667517157293.png

 

AFTER:

jennratten_1-1667517180374.png

 

Hey! 

This worked great, thank you

 

Best,

 

Dan

Wonderful!  Please consider giving my solution a thumbs-up and marking it as an accepted solution.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors