Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Optimization with horizontal and vertical checks

daryllj
7 - Meteor

Hi, I'm currently working on a table that includes NetValue, BookValue, and GainLoss (where NV - BV = GL). I need to allocate these values according to a specific ratio, rounding to the nearest whole number.

The problem arises due to the total rounding of values, which will be manually adjusted by a maximum increment of +/- 1 to negate the variance from the original totals. Ideally, I will first check the rows for any variance, then adjust the columns. If there is variance in both, it's a good indicator that the intersected cell should be adjusted.

I'm exploring the Optimization tool but I'm struggling to determine the correct input values for each anchor to make this work. I will be using the Optimization tool to determine the appropriate adjustments.


Input:

  NetValueBookValueGainLoss 
 Original4250.003000.001250.00 
      
 Ratio   Check
A11.80%502.00354.00148.000.00
B21.00%893.00630.00263.000.00
C0.00%0.000.000.000.00
D26.20%1114.00786.00328.000.00
E41.00%1743.001230.00513.000.00
 100.00%4252.003000.001252.00 
 Check-2.000.00-2.00 


Desired output:

RatioNetValueBookValueGainLoss
11.80%501.00354.00147.00
21.00%892.00630.00262.00
0.00%0.000.000.00
26.20%1114.00786.00328.00
41.00%1743.001230.00513.00
100.00%4250.003000.001250.00
3 REPLIES 3
Yoshiro_Fujimori
15 - Aurora
15 - Aurora

Hi @daryllj ,

 

When you show 2 decimal places, it normally means it is rounded to the nearest number to th real value with the precision of 0.01.

The calculated result of your sample data is as below.

If you want to show it with 2 decimal places, you can simply use ".50" with no problem.

NameRatioNetValueBookValueGainLoss
A11.80%501.50354.00147.50
B21.00%892.50630.00262.50
C0.00%0.000.000.00
D26.20%1113.50786.00327.50
E41.00%1742.501230.00512.50

 

Otherwise if you really want to show the number in Integer and still want to adjust the sum,

you would need to define conditions of when to round-up and when to round-down.

But it does not seem to be an essential problem to take a time...

daryllj
7 - Meteor

Hi @Yoshiro_Fujimori ,

Yes, I think I presented my sample incorrectly. The significant values should be rounded to the nearest whole number only. You could eliminate the decimals instead. However, strictly adjust the allocation after checking for variance in the rounding totals.

Unfortunately, I need this optimization because multiple adjustments will need to be made on a daily basis.

Yoshiro_Fujimori
15 - Aurora
15 - Aurora

Though the decision logic to select the rows to round up is not clear,

the attached workflow output the data mostly the same as you expect.

I hope this helps.

 

Workflow

workflow.png

Formula #1

[Value2] = [Ratio] * [Value]

[RoundDown] = FLOOR([Value2])

[Diff] = [Value2] - [RoundDown]

 

Formula #2

[Diff] = IF [Count] <= [Sum_Diff] THEN 1 ELSE 0 ENDIF

[Value2] = [RoundDown] + [Diff]

 

Output

NameRatioNetValueBookValueGainLoss
A0.118501354147
B0.21892630262
C0000
D0.2621114786328
E0.4117431230513
Total 425030001250
Labels
Top Solution Authors