Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

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

Creating ratio columns

amits
5 - Atom

I have a set of columns in my dataset which follow this pattern: currentIncome, AvgIncome, currentSalary, AvgSalary, currentNetWorth, AvgNetworth. I now want to get ratio columns for these e.g ratioIncome, ratioSalary, ratioNetWorth which will be calculated as ratio = current / Avg. How can I achieve this? I dont want to hard code because there are going to be hundereds of such columns.

3 REPLIES 3
neilgallen
12 - Quasar

@amits 

 

The idea here is to transpose the data so your fields are now records and not fields. From there you can use one formula tool to complete the math, regardless of the number of fields at play. This assumes the schema is similar with "avg" or "current" as a suffix for each field.

 

The attached workflow should get you there, but attaching a sample of the dataset would guarantee that it gets the answer you're looking for.

 

 

danilang
19 - Altair
19 - Altair

Hi @amits 

 

Any time you have a dynamic set of columns that you need to process, the best way to go about is to transpose the columns so that they become a set of name/value pairs that can be worked on with a minimum number of tools.  This ensures that new columns will be automatically processed

 

WF.png

 

First add a recordID to rebuild the original row structure at the end.  Transpose and build scaffolding columns to ensure that the crosstab columns come out in the right order.  After building the Ratio and RatioName columns split the columns and union them back to get the ratios and ration names in the same columns.  Finish off with a sort, crosstab and dynamic rename to get your final columns in the proper order with the correct names

 

Results.png

 

Dan

amits
5 - Atom

Thanks for the solutions @neilgallen @danilang 

Labels
Top Solution Authors