Join the Alteryx Community’s Maveryx Summer Cup event! Compete, network with others, and earn your gold through a series of challenges from July 24th to August 11th. Learn more about the event here.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Multiple String Replacements in Field Names Using Dynamic Rename Tool

JakeW
7 - Meteor

Howdy,

 

I am attempting to dynamically provide a list of file names in a list box inside an app. I have a couple of patterns of characters within my field names, which I would like to replace out before they are presented to the user. For instance, "___"  (three underscores), I would like to show as " - " (space dash space). Also, in the same field names, it now shows "_dbf" after the cross tab tool. I would like to change those back to a normal extension of ".dbf" (dot dbf). 

 

My question is, is there a way to do this, without using multiple dynamic rename tools? Is there a Regex_Replace function I could use? You can see in the screenshot below I tried two replace expressions separated by an OR statement and that did not work. If I have to use multiple dynamic renames, I will do that, but I feel like there is a way to simplify this. Thanks ahead of time for any help on this!

 

Screenshot 2021-05-19 153206.jpg

9 REPLIES 9
apathetichell
19 - Altair

Dynamic Rename uses standard IF/Then/Else formatting. your idea should be fine if you adjust for that format. Not sure how a regex could work.

 

so basically:

 

if contains([_currentfield_],"_") then replace([_currentfield_],"_","-") else replace([_currentifled_],"-dbf",".dbf") endif

 

or something like that - I'd do the .dbf change first since it includes "_" but is more specific.

JakeW
7 - Meteor

Thanks!

 

It seems like it's taking the first replace in the if then logic, but not the second replace...

 

JakeW_0-1621458171656.png

 

 

KarolinaRoza
11 - Bolide

Hi,

Did you try just to apply two Dynamic Rename tools with formulas:

first with :

Replace([_CurrentField_],"_dbf",".dbf")

and second with :

Replace([_CurrentField_],"___","-")

 

I think it should work.

 

Regards,

Karolina

apathetichell
19 - Altair

hmm it should be working - if you post your fieldnames I can take a look at it - but my expectation is that the exact characters aren't matching. if you do something like "__" or even "_" as a test run you can see what the composition looks like. But the strategy should be the same... Also - not sure if it's case sensitive but if it is you can wrap each entry in an uppercase() function.

 

But keep in mind that the if/then combo will only do one replace at once. You can do a nested replace like

 

replace(replace([_currentfield_],"_dbf",".dbf")"___","-") and see how that looks.

JakeW
7 - Meteor

Thanks Karolina!

 

I did. And that definitely works. I was just curious if there was a way to consolidate the dynamic renames, as i'm actually going to end up having more than just the two I provided in the above example. I was hoping just one dynamic rename with replacement logic would work for all the clean up, but definitely not the end of the world if it doesn't. 

JakeW
7 - Meteor

apathetichell,

 

I've attached the list of field names i'm attempting to clean up. Let me know what you think. Thanks again!!!

apathetichell
19 - Altair

This is how I'd do it---- it uses the dynamic rename but it takes the info from the right anchor and you can perform granular fieldname changes in the formula tool with greater transparency...

JakeW
7 - Meteor

I dig this solution. This worked great. Thank you! This is still better than having to do 5 different dynamic renames in my opinion. Thanks again!

apathetichell
19 - Altair

Thanks! - Glad to help.

Labels