Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Community is experiencing an influx of spam. As we work toward a solution, please use the 'Notify Moderator' option on the ellipsis menu to flag inappropriate posts.

Alteryx Designer Desktop Discussions

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

Iterative Macro - Can only stop loop by defining maximum iterations

data4accounting
7 - Meteor

I have built an iterative macro where the full output including the records that were output in the current iteration and not just the output for the remaining records needs to feed back into the macro input because the outputs from each iteration drive the calculations for the next iteration. I have finally got this macro to work by having the loop and output be the same and setting the maximum iterations equal to the iterations I need ie the total transfer order and the final result I need is the output from the loop node. I have tried a number of different other methods to try to get the correct result and have the iterations stop dynamically instead of forced but I have not been able to come to a solution and I was hoping someone had an idea here. Thanks!

3 REPLIES 3
danilang
19 - Altair
19 - Altair

Hi @data4accounting 

 

You can accomplish this by adding the logic that terminates the macro into the macro itself.

danilang_0-1683288835270.png

 

The attached macro two containers.  The top one contains the logic the you have in your existing macro.  The bottom one contains the Macro exit logic.   The output of the Exit Logic container is a single Boolean value [ExitMacro]  This value is appended to all the records that result from your operation logic.  The ExitMacro Filter tool has a single condition [ExitMacro] = 1 or true in this case.  All the records that satisfy this are sent to the data output of the macro. All the records that fail the condition are sent to to the iterative output.  Since [ExitMacro] is the same for all records, the filter acts as a switch that either sends all records to the iterative output while still looping or to the data output when finished.  Since an iterative macro will loop until there are no records in the input OR max iterations is reached, this technique will keep looping until the [ExitMacro] condition is True

 

In this simple example the exit logic is simply the sum of all the records >= 10, but you can modify the logic as required

 

Dan 

 

 

data4accounting
7 - Meteor

Thank you @danilang! In theory, I think what I have attached should be working. When I run it within the macro and force the count to equal 21 then it works as expected where nothing comes out of the loop output but when I attach it back to my main workflow, the iterations do not stop at the 21 specified and instead the macro continue to run/iterate until the maximum iterations. I tried something similar to your solution last night and got the same results. Any thoughts here? Much appreciated! 

data4accounting
7 - Meteor

@danilang, I found the issue! I thought I unchecked the exitmacro from the select tools but I did not so it was just appending a new existmacro field each run but now it works! 

 

Labels