We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Dynamically select column based on information from another column

stephouyang
5 - Atom

Hi, 

 

I'm trying to select all the columns that end in the value of the last column. How can I do that? 

 

 

My last column is dynamic, for period 1 it will show _1, period 2 it will show _2, etc.

 

When it's period _1 (which is the last column in the input file), I want to select 2 columns "PERIOD_1" & "C_PERIOD_1".

 

When it's period _2 , I want to select 2 columns "PERIOD_2" & "C_PERIOD_2".

 

 

Attached a sample input file.

 

Many thanks! 

10 REPLIES 10
flying008
15 - Aurora

Hi, @stephouyang 

 

Maybe the dynamic select solution is just your want:

 

录制_2023_04_22_11_46_26_436.gif

 

BTW, you select condition is by last column' name or the end-line value of last column? 

 

 

Yoshiro_Fujimori
15 - Aurora
15 - Aurora

Hi @stephouyang ,

 

I understand you want to specify period "dynamically" specify from other input.

So I used a macro as below. If you want to make it a drop-down list, that would be also easy.

 

Workflow

Yoshiro_Fujimori_0-1682139440024.png

Macro

Yoshiro_Fujimori_1-1682139472060.png

Input data for "Period"

Yoshiro_Fujimori_3-1682139561626.png

 

Output

Yoshiro_Fujimori_2-1682139509589.png

 

flying008
15 - Aurora

Hi, @Yoshiro_Fujimori 

 

Dear Sir, IMHO, Crosstab tool involves the operation of field names. If the field names of the current data contain special characters like ~^&*()[], it is likely that the expected results will not be obtained, so corrections or other solutions are required to handle the needs of this scenario.

Yoshiro_Fujimori
15 - Aurora
15 - Aurora

Hi @flying008 ,

 

Thanks for the comment. You are correct that the issue can happen if the column names contain special characters.

Your solution also includes Cross Tab tool.

Does it work when the data contains special characters in column names? (The Union tool does the trick?)

If possible, could you attach your workflow?

 

Hi @stephouyang ,

 

After review of the original question, now I understand what you mean by "the last column".

So I corrected my workflow as below.

Yoshiro_Fujimori_0-1682145123580.png

 

Yoshiro_Fujimori_1-1682145152618.png

 

Yoshiro_Fujimori
15 - Aurora
15 - Aurora

Hi @flying008 ,

 

I added some tools to deal with special characters, and a bug fix to the main workflow.

Thanks for the suggestion. It was fun.

 

Main workflow

Yoshiro_Fujimori_0-1682172130381.png

 

Macro

Yoshiro_Fujimori_6-1682172534552.png

 

Input

Yoshiro_Fujimori_7-1682172655498.pngYoshiro_Fujimori_8-1682172710020.pngYoshiro_Fujimori_9-1682172752264.png

 

Output

Yoshiro_Fujimori_10-1682172829960.png

 

 

flying008
15 - Aurora

Hi, @Yoshiro_Fujimori 

 

Dear, thank you for your share.

As my workflow, my cross tab tool is a special version by customized, it can retained all original field name.

So, I building a trick for get same output by dynamic rename.

 

录制_2023_04_24_10_29_37_865.gif

ArtApa
Alteryx
Alteryx

Hi @stephouyang - Here is one more solution:

ArtApa_0-1682311080266.png

 

Yoshiro_Fujimori
15 - Aurora
15 - Aurora

@ArtApa ,

This use of Multi-Field Formula and Data Cleansing is cool !!

Thank you for sharing.

SPetrie
13 - Pulsar

Just adding another variation of a solution.

You can use a dynamic rename to update the description of the columns you wish to keep and then dynamic select to select only those.

SPetrie_0-1682364305336.png

SPetrie_1-1682364357711.png

 

 

Labels
Top Solution Authors