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:
https://gallery.alteryx.com/#!app/Lag-Records-Macro/5d31b2aa0462d70db4d298f4
Hope this is useful for the one or other Alteryx User!
Best wishes
Oliver
Sure welcome 🙂
Hi OliverW
Thanks for this very useful tool!
Is it possible to add a way to group the lagged variables based on another column?
Hi @Rasmuslarsen ,
that should be doable, now the Lag Macro is not locked, care to give it ago and share with the community when you are successfull? Happy to help if you run into any issues or questions.
Best wishes
Olli
Hi @OliverW
Thanks for your reply. I will try to iterate on the macro when I have some spare time 🙂
Best regards,
Rasmus
Hello,
Has this macro been taken down?
I can't seem to find it using the provided link nor through searching the gallery tab.