Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Community is experiencing an influx of spam. As we work toward a solution, please use the 'Notify Moderator' option on the ellipsis menu to flag inappropriate posts.

Alteryx Designer Desktop Discussions

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

Dynamic Rename using conditional logic

MeanLeanDean
8 - Asteroid

I have a situation where I need to dynamically rename some columns that but not others. The challenge arises because the columns I want to change are month/year that change month to month.  I need to dynamically the first image of columns to look like the second image.  Any logic I try to use in the expressions field does nothing.  In all cases the tool accepts the expression, but the expression is ignored.  In all cases, the 

 

Here are a few I have tried to no avail.

 

a. IIF([_CurrentField_] IN ("sort_order","mtd_reporting","branch","state"),[_CurrentField_],Replace(Right([_CurrentField_],Length([_CurrentField_])-4),"_"," ")) 

 

b. IF [_CurrentField_] IN ("sort_order","mtd_reporting","branch","state") THEN [_CurrentField_]

ELSE Replace(Right([_CurrentField_],Length([_CurrentField_])-4),"_"," ")
ENDIF

 

c. IF ToNumber(Left([_CurrentField_],1)) >= 0
THEN Replace(Right([_CurrentField_],Length([_CurrentField_])-4),"_"," ")
ELSE [_CurrentField_]
ENDIF

 

If I manually check all the dated columns and none of the others, it works fine.  But that's not "dynamic" in the way I need it.

 

What am I doing wrong?

 

From this...

MeanLeanDean_0-1654898614954.png

 

To this...

MeanLeanDean_1-1654898671047.png

 

Configuration:

MeanLeanDean_0-1654904769304.png

 

 

6 REPLIES 6
Qiu
21 - Polaris
21 - Polaris

@MeanLeanDean 
Based on my test, you are on the right track.
I only added a RegMatch function to judge if the Filed Name is in the patter of "3digit_3 Letters_4 digits", then the rest is just same as your formula.

0611-MeanLeanDean.PNG

binuacs
21 - Polaris

@MeanLeanDean Another way of doing this with the string functions

 

IIF(EndsWith([_CurrentField_],'_'+toSTring(DateTimeYear(DateTimeNow()))),
Replace(SubString([_CurrentField_],FindString([_CurrentField_],'_')+1,Length([_CurrentField_])),'_',' '),[_CurrentField_])

 

binuacs_0-1654932123167.png

 

MeanLeanDean
8 - Asteroid

Thanks, @Qiu and @binuacs , for your responses.  Like my attempts, your recommendations on work for fields that are checked in the field selection window. They don't work if all that is checked is "Dynamic or Unknown Fields", which I need it to do because the field names change dynamically from month to month and I'm trying to avoid having to manually check the box for each new month every month.

binuacs
21 - Polaris

@MeanLeanDean Both the solutions are dynamic, first it checks for the field names ends with current year then applying the logic only for those field names. If you are getting different output can share some more sample data end expected result

Qiu
21 - Polaris
21 - Polaris

@binuacs 
Thank you for the comments.
I also believe they are all dynamic. 😀

MeanLeanDean
8 - Asteroid

The first image in the original post is the source and the result when the tool is configured as in the image above, hence the need for the conditional logic to ensure that only the date fields are modified.  It's as if the tool is no working as advertised.

Labels