Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

formula combining rand() and sum() in Alteryx

jeanilieski
8 - Asteroid

Hi everyone. I was wondering there is formula that would combine rand() and sum() in Alteryx. I have a simple example in the attached file.

In the column “ff” I would like to have random numbers between 0-2 which sum per “segment_id” and would be equal to the number in the column “final Anmelder”.

 

Thank you for your help!

5 REPLIES 5
danilang
19 - Altair
19 - Altair

Hi @jeanilieski 

 

Do the random numbers have to be integers?  The final Anmelder values in Segment 1235 and 1976 are decimals.

 

Dan

mmenth
11 - Bolide

Hi @jeanilieski,

 

First off, good question by @danilang-- my solution assumes that you do indeed want integers. Basically what I've done in the attached is made an iterative workflow where for each segment it generates numbers between 0 and 2 until the sum of those numbers equals the number in the “final Anmelder” field. 

 

I suggest forcing any of your decimals to be integers at the beginning, otherwise we'll have to do something else if you truly want the numbers to be random decimals.

 

Best,

mmenth

jeanilieski
8 - Asteroid

thank you a lot @mmenth, it works perfectly. and you are right I prefere to have absolute numbers here. 

jeanilieski
8 - Asteroid

I  am sorry to continue the discussion here @mmenth , but when I tried your macro on a larger dataset I receive an error "Iteration limit of 100 was reached". Could you please suggest how to increase the limit or simply set it to no limit? 

 

Thank you!

jeanilieski
8 - Asteroid

Thank you @mmenth , but I already found the solution on the youtube video for Iterative Macros. Have a great day!

Labels