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

pick random value of a column until x is reached

df
8 - Asteroid

Hello guys,

 

i have a table with 3 columns of different dimensions and a column with values.

Sum_Value has the grouped Value by Dimension a.

Weight is different fo each Dimension a.

 

Now I'm searching for a methode which randomly allocate the Values until the Sum of this new column reached Sum_Value_Weighted.

 

Is there a way to do that?

 

Dimension aDimension bDimension cValueSum_ValueWeightSum_Value_WeightedOutput_Value (Example)Output_Value (Example 2)
a1b1c1390.4412
a1b2c1290.4410
a1b3c1190.4401
a1b1c2190.4411
a1b2c2190.4400
a1b3c2190.4410
a2b1c1270.8622
a2b2c1170.8610
a2b1c2270.8612
a2b2c2270.862

2

5 REPLIES 5
Thableaus
17 - Castor
17 - Castor

Hi @df 

 

I'm not sure if I followed, but I developed a solution with an Iterative macro.

 

Please check the workflow and also the macro and let me know if you have any doubts.

 

Just pointing out that the "Output Value" column is going to change dynamically every time you run the workflow, because a new value is going to be randomly generated.

 

Cheers!

df
8 - Asteroid

Hi @Thableaus 

 

thanks for the answer.

 

I think i was i little bit to fast with accepting it as a solution. The Output Value should never be higher than the column 'Value'.

The Idea is to say, that we have a sum of x Values ('Sum_Values') in column 'Value' for each Dimension a.
We weight the Sum_Value with the Weight -> y 'Sum_Value_Weighted'

Now i know, that i want to randomly select y Values from the column 'Value'.

grafik.png

df
8 - Asteroid

@Thableaus  hello again,

i developed a own solution with a batch macro (level 1) & a iteration macro (level 2)

each dimension a is a batch.

in each batch i select a random row until condition is reached (enought values picked). When row is selected i check if value is under weighted_Value if yes weighted_value + 1
if not weighted_value 

 

Then weighted_value  cant exceed value.

 

I attached the macros and workflow but there are a little bit messy. (created some columns i did not need ect.)
Just started with macros today :)

Thanks, your answer inspired me to learn this macro stuff.

Edit: Oh, I can't attach files
i get error "The contents of the attachment doesn't match its file type."

 

Edit 2: I'll attached some pictures just in case someone has same problem.

 

Edit 3: I have attached the file now. I changed it a little bit so the screenshots look a little bit different compared to the file attached.

 

grafik.png

Thableaus
17 - Castor
17 - Castor

Hi @df 

 

So happy that I made you learn something. This is the main point of my participation in the community.

I did not know about this condition (output value can't be greater than value). But good to know you found a workaround.

You can export your workflow as a .yxzp package. 

 

Option.png

 

Cheers,

Thableaus
17 - Castor
17 - Castor

@df 

 

I also recommend you to mark your own post with the full solution as a topic solution.

 

Cheers,

Labels