Alteryx Designer Desktop Discussions

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

Repetitive formula to create new columns

harshendra
8 - Asteroid

Hello folks!

 

I am currently using Formula tool to generate new rows that have repetitive formula but using different columns. Is there a way that I do not need to re-write the same formlua for many columns? 

 

I have two sources of data.

 

Source Data: that has product amounts by each ID.

 

IDProduct_123_AmtProduct_ABC_AmtProduct_XYZ_Amt
AA14041.5828735.4393896.96
BB16453.2162606.228602.4
CC83453.4918025.1254810.77
DD4219.1148773.527987.05
EE28193.8815343.1395670.15
FF73438.0379550.6167179.56
GG10098.6796634.9327446.76
HH46252.5153855.2948126.03
II58690.788955.5655635.67
JJ94182.5897780.4811577.28

 

Actual Amount: which should be the actual total amount for each product.

Actual_Product_123_AmtActual_Product_ABC_AmtActual_Product_XYZ_Amt
46105.4511162.6710479.54

 

I need to pro-rate the amount by ID in Source Data such that the totals become equal to Actual Amount.

 

This involves two steps.

1. To get the total from Source Data (Sum_Product_123_Amt, Sum_Product_ABC_Amt, SUM_Product_XYZ_Amt)

2. Apply the formlua Final_Product_Amt = [Product_Amt]/[Sum_Product_Amt]*[Actual_Product_Amt] 

 

This gives me the below output which is correct.

 

IDProduct_123_AmtSum_Product_123_AmtActual_Product_123_AmtFinal_Product_123_AmtProduct_ABC_AmtSum_Product_ABC_AmtActual_Product_ABC_AmtFinal_Product_ABC_AmtProduct_XYZ_AmtSum_Product_XYZ_AmtActual_Product_XYZ_AmtFinal_Product_XYZ_Amt
AA14041.58429023.8446105.451508.99158628735.43510260.2511162.67628.628474293896.96510932.6310479.541925.883943
BB16453.21429023.8446105.451768.15966962606.2510260.2511162.671369.59982828602.4510932.6310479.54586.6526765
CC83453.49429023.8446105.458968.40770118025.12510260.2511162.67394.325182654810.77510932.6310479.541124.202337
DD4219.11429023.8446105.45453.410619748773.5510260.2511162.671066.98980627987.05510932.6310479.54574.0314725
EE28193.88429023.8446105.453029.881815343.13510260.2511162.67335.6528395670.15510932.6310479.541962.253152
FF73438.03429023.8446105.457892.08688379550.61510260.2511162.671740.28293967179.56510932.6310479.541377.893767
GG10098.67429023.8446105.451085.26305896634.93510260.2511162.672114.02678227446.76510932.6310479.54562.9497949
HH46252.51429023.8446105.454970.56943853855.29510260.2511162.671178.16120348126.03510932.6310479.54987.0942406
II58690.78429023.8446105.456307.2598088955.56510260.2511162.67195.915635155635.67510932.6310479.541141.121539
JJ94182.58429023.8446105.4510121.4194497780.48510260.2511162.672139.0873211577.28510932.6310479.54237.457077

 

So, I am able to achieve the end results with Formula tool. Now here I am showing three products, but in reality I have around 50+ products. As of now I am creating the Final column with the help of Formula tool. But I will need to repeat the formula 50 times and the products will vary. Is there a way using which I can do what I am doing without the need of writing the formula 50 times?

 

 

Thanks,

Harshendra

5 REPLIES 5
TimN
13 - Pulsar

This seems to work but I struggle with Dynamic Replace and if it really fits in this use case.  

abe_ibanez
8 - Asteroid

Hello, 

 

When I have to work with many columns that have the same structure, I normally transpose the data to allow me to more easily manipulate all at once. 

After you are done with your calculations, you can cross-tab it back to the original format. 

Here is an example: 

image.png

 

The top input is the current data. 

The bottom input is the total it should add up to. I used a dynamic input tool to get rid off the "Actual_" so that the fields would match. 

After the first transpose on the top data stream, I used a summary tool to calculate the current sums. With that, I appended what the actual amount should be to calculate the weight for the scalar. I then joined that weight to the transposed data to the corresponding product. After scaling the values with that weight, I cross-tabbed the data back into its original form. 

This should work for any number of products. 

 

I hope this helps :) 

binuacs
20 - Arcturus

@harshendra One way of doing this with the batch macro

image.png

Qiu
20 - Arcturus
20 - Arcturus

@harshendra 
For dynamic columns, it is always effective to use the combination of Transpose and Cross Tab. 😁

1216-harshendra.png

harshendra
8 - Asteroid

Thanks all, I will try transpose and crosstab approach and update the topic.

Labels