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.
Solved! Go to Solution.
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.
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
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
Dan
Thanks for the solutions @neilgallen @danilang