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!
Solved! Go to Solution.
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
If you are looking for loop iteration based on condition in alteryx.
Iteration macro is thing you are looking for.
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 Name | Seller Type | Rate / LB | 1 LB Bags | 3 LB Bags | 5 LB Bags | 10 LB Bags | 20 LB Bags | Count |
Apple | Direct | 6 | Yes | No | Yes | Yes | Yes | 3 |
Apple | Indirect | 4 | Yes | No | Yes | Yes | Yes | 3 |
Apple | Indirect | 6 | No | No | No | No | Yes | 3 |
Orange | Direct | 7 | No | No | Yes | No | Yes | 4 |
Orange | Direct | 5 | No | No | Yes | Yes | Yes | 4 |
Orange | Indirect | 6 | No | No | Yes | Yes | Yes | 4 |
Orange | Indirect | 5 | Yes | No | No | No | No | 4 |
Mango | Direct | 4 | Yes | Yes | Yes | Yes | Yes | 3 |
Mango | Indirect | 5 | Yes | No | No | Yes | Yes | 3 |
Mango | Indirect | 6 | Yes | Yes | Yes | Yes | Yes | 3 |
Pineapple | Direct | 6 | No | No | No | Yes | Yes | 6 |
Pineapple | Indirect | 2 | No | No | Yes | Yes | Yes | 6 |
Pineapple | Indirect | 3 | No | No | No | Yes | Yes | 6 |
Pineapple | Direct | 7 | Yes | No | Yes | Yes | Yes | 6 |
Pineapple | Indirect | 8 | Yes | No | No | No | Yes | 6 |
Pineapple | Indirect | 4 | Yes | No | No | No | Yes | 6 |
Kiwi | Direct | 3 | Yes | Yes | Yes | Yes | Yes | 2 |
Kiwi | Indirect | 3 | Yes | No | No | Yes | Yes | 2 |
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?
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 Name | Seller Type | Rate / LB | 1 LB Bags | 3 LB Bags | 5 LB Bags | 10 LB Bags | 20 LB Bags | Count |
Apple | Direct | 6 | Yes | No | Yes | Yes | Yes | 3 |
Apple | Indirect | 4 | Yes | No | Yes | Yes | Yes | 3 |
Apple | Indirect | 6 | No | No | No | No | Yes | 3 |
Orange | Direct | 7 | No | No | Yes | No | Yes | 4 |
Orange | Direct | 5 | No | No | Yes | Yes | Yes | 4 |
Orange | Indirect | 6 | No | No | Yes | Yes | Yes | 4 |
Orange | Indirect | 5 | Yes | No | No | No | No | 4 |
Mango | Direct | 4 | Yes | Yes | Yes | Yes | Yes | 3 |
Mango | Indirect | 5 | Yes | No | No | Yes | Yes | 3 |
Mango | Indirect | 6 | Yes | Yes | Yes | Yes | Yes | 3 |
Pineapple | Direct | 6 | No | No | No | Yes | Yes | 6 |
Pineapple | Indirect | 2 | No | No | Yes | Yes | Yes | 6 |
Pineapple | Indirect | 3 | No | No | No | Yes | Yes | 6 |
Pineapple | Direct | 7 | Yes | No | Yes | Yes | Yes | 6 |
Pineapple | Indirect | 8 | Yes | No | No | No | Yes | 6 |
Pineapple | Indirect | 4 | Yes | No | No | No | Yes | 6 |
Kiwi | Direct | 3 | Yes | Yes | Yes | Yes | Yes | 2 |
Kiwi | Indirect | 3 | Yes | No | No | Yes | Yes | 2 |
Hi @Santy ,
Your use case can be solved much very easier way.
Please see my approach.
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
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
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.