Alteryx Designer Desktop Discussions

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

For Loop Iterations

Santy
7 - Meteor

How do we perform for loop iterations on Alteryx? I have a situation where I need to validate some conditions for a group in list of records. If any of the conditions is met, the loop should break/end for that group and perform same steps for the next group in that list. Please guide me. Thanks!

10 REPLIES 10
brendafos
10 - Fireball

Could you provide a sample of what you want to do?  Or just state more details.

 

It could be that you just need to use the 'IN' operator.

 

Here's a link to a good discussion of when and how to use IN

https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Difference-between-In-function-and-Con...

atcodedog05
22 - Nova
22 - Nova

If you are looking for loop iteration based on condition in alteryx.

 

Iteration macro is thing you are looking for.

Santy
7 - Meteor

@brendafos 

 

Here is an example. From the table below, I need to get 5 rows in the output based on the conditions.

 

1. If there is a direct seller, pick that row. 

2. If there are more than one direct seller, pick the one who has 5LB and 20 LB Bags.

3. If there are more than one row for same fruit with direct seller and has both 5 and 20 LB bags, pick the lowest Rate among those selected rows.

 

If any condition matches for a fruit, ignore the rest of the rows for the specific fruit and go to next fruit and validate.

 

Fruit NameSeller TypeRate / LB1 LB Bags3 LB Bags5 LB Bags10 LB Bags20 LB BagsCount
AppleDirect6YesNoYesYesYes3
AppleIndirect4YesNoYesYesYes3
AppleIndirect6NoNoNoNoYes3
OrangeDirect7NoNoYesNoYes4
OrangeDirect5NoNoYesYesYes4
OrangeIndirect6NoNoYesYesYes4
OrangeIndirect5YesNoNoNoNo4
MangoDirect4YesYesYesYesYes3
MangoIndirect5YesNoNoYesYes3
MangoIndirect6YesYesYesYesYes3
PineappleDirect6NoNoNoYesYes6
PineappleIndirect2NoNoYesYesYes6
PineappleIndirect3NoNoNoYesYes6
PineappleDirect7YesNoYesYesYes6
PineappleIndirect8YesNoNoNoYes6
PineappleIndirect4YesNoNoNoYes6
KiwiDirect3YesYesYesYesYes2
KiwiIndirect3YesNoNoYesYes2
Santy
7 - Meteor

@atcodedog05 

 

Am new to the tool and learning on how to use it. I have provided some sample data in my response to explain what I am looking for. Are there any tutorials that I can refer to for learning how to build iteration macro?

Santy
7 - Meteor

@brendafos 

 

Here is a sample data.

 

As an output, I need to get 5 rows (1 row each for a fruit) with some conditions as below:

 

1. If a fruit has only one row with seller type as DIRECT, pick it.

2. If a fruit has more than one rows with Direct and Indirect seller, pick the direct seller type.

3. If a fruit has more than one rows with more than one Direct seller, pick the row that has 5 and 20 LB Bags as YES.

4. If a fruit has more than one rows with more than one Direct seller and more than one rows that has 5 and 20 LB Bags as YES, then pick the row that meets all of the conditions and has a SMALLER Rate/LB.

 

As soon as a row meets one of the conditions above, it should ignore (BREAK THE LOOP) the other rows for same fruit and check for the next fruit for the same conditions.

 

Fruit NameSeller TypeRate / LB1 LB Bags3 LB Bags5 LB Bags10 LB Bags20 LB BagsCount
AppleDirect6YesNoYesYesYes3
AppleIndirect4YesNoYesYesYes3
AppleIndirect6NoNoNoNoYes3
OrangeDirect7NoNoYesNoYes4
OrangeDirect5NoNoYesYesYes4
OrangeIndirect6NoNoYesYesYes4
OrangeIndirect5YesNoNoNoNo4
MangoDirect4YesYesYesYesYes3
MangoIndirect5YesNoNoYesYes3
MangoIndirect6YesYesYesYesYes3
PineappleDirect6NoNoNoYesYes6
PineappleIndirect2NoNoYesYesYes6
PineappleIndirect3NoNoNoYesYes6
PineappleDirect7YesNoYesYesYes6
PineappleIndirect8YesNoNoNoYes6
PineappleIndirect4YesNoNoNoYes6
KiwiDirect3YesYesYesYesYes2
KiwiIndirect3YesNoNoYesYes2
atcodedog05
22 - Nova
22 - Nova

Hi @Santy ,

 

Your use case can be solved much very easier way.

 

Please see my approach.

atcodedog05_0-1589384757381.png

Please check whether this solve your use-case successfully. 

 

Please do reply back to me with your inputs.

 

Here is a source where you can get to more about iterative macros.

https://community.alteryx.com/t5/Videos/Advanced-Certification-Prep-Part-II/td-p/351833

atcodedog05
22 - Nova
22 - Nova

Hi @Santy ,

 

I can see you had a similar issue last time was it solved ?

https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Conditions-Looping-Through-Multiple-Lo...

 

Happy to help : )

Santy
7 - Meteor

Hi @atcodedog05 

 

This worked exactly the way I wanted. Thank you so much for guiding. I did not know about the SORT feature and was working to solve this with multiple IFs and JOINs.

 

Thanks again!!

 

regards,

Santosh

Santy
7 - Meteor

Hello @atcodedog05,

 

Today's solution worked. Did not get much from the other thread. So, thought of posting with a good data and proper explanation. 

Labels