Alteryx Designer Desktop Discussions

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

Iterative Macro stop conditions best practices

17 - Castor
17 - Castor

Hi all, 

I was looking at tackling weekly challenge 240 when I ran into an issue stopping my iterative macro, I have attached my full workflow. I wanted my macro to stop once the my macro 'output' (not the iterative output) received some data. However, the way my macro was set up some data was still being passed to the iterative output causing the macro to keep iterating unnecessarily. I fixed this by appending some fields to check against (shown in the screen shot below). 


Is there a more efficient way of stopping the iteration? Any tips on how to structure iterative macros would be much appreciated. Would it make sense for iterative macros to have a tool/configuration to stop iteration based on a condition rather then stopping based on the number of rows in the 'iteration output'?


In the workflow I've included two versions of the macro one with my checks and one without to show the iteration issue.  


One note on the task, with the number of iterations needed being unknown I don't think setting a maximum number of iterations makes sense in this scenario.  

Alteryx Alumni (Retired)

Hi  @IraWatt ,


Great question, in programming languages you would usually have a while-loop with the stop condition directly at the start. e.g. "while percentage <= 50".


In Alteryx, the stop condition can be the following:

Batch Macro: stops after looping over all records from the control parameter.

Iterative Macro: stops once the loop output is empty, OR the maximum number of iterations is reached.


To include a stop condition like 'percentage >= 50', the loop output needs to be empty once the condition is met.

An easy way to achieve this is to create a new field checking if the condition is true or false. You append this value to the dataset just before the loop output and use a filter checking if it is true or false. This results in an empty dataset if the condition is true and thus stops the loop.

You did this already in your macro. And you can look at other solutions to challenge 240 for further examples.


Best practice is always to make this clear in your workflow, so you and others understand it easily. For example using tool annotations and tool containers. See my solution to challenge 240 attached.


240 - loop condition.jpg



Please mark this as the solution if it answers your question, it will help others to find solutions quicker.

Kind Regards,
Solutions Engineer - Alteryx

12 - Quasar

Hi @IraWatt 


Perhaps I may not be understanding fully, but can you make use of either or both TEST and MESSAGE tools in either your macro or workflow?