Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

Alteryx Lag Macro


Ever in need of "lagging" your data?


As I heard in many customer conversations, one feature people built for predictive models is a "Lag Feature".


Basically this means pulling a specific value from a specific field from the previous record into a new column of the actual record, looking like this:



 As you can see here, for the row 2, for column Lag-1 it pulled down the value from the previous row (1) .


You could achieve this generally by using one (or like in the above picture multipl) Multi-Row Formula Tools within Alteryx. Now, in order to be able to create as many "Lag Fields" that you need, I have created a Lag Record Macro. All you do is, you select how many rows before you want to start "lagging", how many rows you want to lag (essentially how many columns for lags you want to generate) and then select the Field (must be Numeric) which should be lagged, so basically a value field.


Once you have lagged you can also very easily calculate the difference between the actual row value and the lagged values for multiple columns (if you need to) by just using a "Multi-Field Formula" Tool afterwards.


You can download the tool in the Alteryx Gallery, it's a yxi Installer:!app/Lag-Records-Macro/5d31b2aa0462d70db4d298f4


Hope this is useful for the one or other Alteryx User!


Best wishes