Half a day with Maia. A working pipeline by the end.

Register

Using Lead/Lag in Matillion

Data is powerful, but only as powerful as the ability to analyze it. Matillion offers a powerful tool, the Lead/Lag component, to enhance data analysis. The Lead/Lag tool allows users to easily access values from preceding and following rows within a partition.

This is very useful for time-based analyses like year-over-year and month-over-month comparisons. We'll walk you through what Lead and Lag functions are, their use cases, and how to effectively use the Matillion Lead/Lag Component in your workflows.

What are Lead and Lag functions? 

Before diving into the Matillion component, it's important to understand what the Lead and Lag functions do. 

Lag

This function accesses data from a previous row in the same result set without needing a self-join. For example, it can be used to calculate the difference between the current row and the previous one. 

Lead

While Lag looks at previous rows, Lead looks at the following rows. This function is most often used to compare the current row with a future value.

Setting up Lead and Lag functions 

Together, Lead and Lag functions are often used in time series analysis, trend analysis, and when comparing values across rows.

For example, let’s compare the sum of profit by item month over month. To do this we create a Transformation pipeline and use a table input component to use the profit_by_item table in Snowflake. 

Next, we drag the Lead/Lag component onto the canvas and connect it to the Table Input component. 

To configure the component, we use the following settings:

Include Input ColumnsYes
Partition Dataitem_name
Orderings Within Partitionorder_month
FunctionsLead
Ignore NullsNo

This process lets us easily handle month-over-month calculations by dragging the Calculator component onto the canvas and connecting it to the Lead/Lag component. 

This step uses the following configuration:

Include Input ColumnsYes
Calculations1 - (“sum_profit”/”last_month_profit”)

The last step is to make this data accessible. For this step, drag and drop the Create View component and connect it to the Calculator component. From there, right click on the canvas and click Run Pipeline. 

Matillion enables advanced data analysis

Whether you're working with financial data, customer behavior metrics, or sales figures, mastering the Lead/Lag Component in Matillion will enhance your ability to uncover trends and make data-driven decisions. 

The Matillion Lead/Lag Component is a powerful tool for performing advanced data analysis within your workflows by enabling easy access to previous and subsequent rows. This ability allows you to make full use of your company data through tasks like trend analysis and time series comparison. As a result, you gain more insights from your data with minimal effort. 

Ready to supercharge your data analysis? Contact Matillion today for a demonstration and see how its Lead/Lag Component makes complex row-by-row comparisons easy.

Alan Goodrich
Alan Goodrich

Enterprise Solution Engineer

Ready to get moving?

See how quickly your team can start delivering business-ready data, with Matillion.