This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
I am using the dynamic rename tool, using the functionality "Take Fields From First Row of Data". In case there is a repited field, Alteryx uses "_2", "_3", etc. in order to avoid repeating names for different columns. Until here everything works fine.
However, in case I update the input with more columns of data, the order of the repated columns ("_2", "_3", "_4", etc.) for the new columns is altered and generated randomly (e.g., "_7", "_2", "_4", etc. instead of "_2", "_3", etc.).
Exploring ways of solving this issue, I have found that if I Clear and then Select All the fields (in the Dynamic Rename configuration), then everything works fine and the order of the columns is generated correctly.
Is this a bug? How can I solve this without having to select and unselect all the fields everytime I want to run the workflow?
In my input file, the column "_1" always makes reference to a variable, "_2" to another variable, and so on. After reading the file and doing the dynamic rename, with an IF statement I am renaming the names of the columns to the variable they make reference. When the dynamic rename function is not sorting the columns properly I get my variables messed up.
I have thought about other ways of doing this but didn't come up with any possible solution. Unless you find an alternative solution, I think that using your macro is the best option!
Hello again jmelecs. I apologize I still don't fully understand your use case so I can't really suggest another solution.
If you are not comfortable with the macro let me know and we can keep trying to figure out exactly what you need and if there is another solution :-)
I BELIEVE the macro works due to the following reason, however you may want to get direct clarification from an AlterYX team member on this one, as I am simply a user.
When alteryx runs a workflow it stores the metadata of columns coming in and out of the tool. As such after you run the tool the first time it will store the outputs of the columns you passed in. You can see this in the check boxes you mentioned after the tool is run).
Then if you add another column that comes between any of your previously defined fields the following happens.
#1) The system recognizes the columns from the last run, and so it maintains their metadata. All of the new columns fall into the category of "Dynamic or Unknown fields" and therefore the _ values starts at X, where X was the number that had previously run through the system....
To see this do the following. make an input dataset that has row #1 of "123, Brandon, 123" of 3 columns. Run your tool, you should get
"123, Brandon, 123_2". Now add another column of "123" before brandon (second column). "123, 123, Brandon, 123". Now run your tool again... You should be "123, 123_3, Brandon, 123_2"; As you noticed the secondary column now has a value of 123_3 instead of 123_2 like you expected. This is because the sytem meta already set up and registered this column from the last run so your new column went into the "unknown" category, meaning it is read AFTER the columns added to the metadata....
Now here is where it gets fun... Re-run your code AGAIN.... your results will CHANGE too "123, 123_2, Brandon, 123_3"...
This happened because during your second run, it registered your second coulmn (which you re-named to 123_3), and therefore it included it in the list of KNOWN columns instead of "*unknown". Since it was in second ordinal position it got a value of _2.
Why the macro fixes this: I set up the macro to not expect any input what so ever. So what it will do is take exactly the stream of data you pass in. This means EVERY column is an "*unknown" column in a sense, so the naming of the columns is purely based upon their ordinal position, which is exactly what you wanted.
Please Note: This is all based upon my understanding of the tool, so please take that into consideration!