Table of Contents
A lag function in Excel is a formula that allows users to shift data within a spreadsheet by a specified number of rows or columns. This can be useful in analyzing time series data or comparing data from different periods. To create a lag function, users can use the OFFSET, INDEX, or INDIRECT functions in Excel. The OFFSET function allows users to specify a range of cells to shift, while the INDEX function returns a specific cell within a range. The INDIRECT function can be used to reference a specific cell based on a given criteria. Examples of using a lag function in Excel include calculating the percentage change in sales from one month to the next, comparing stock prices over different time periods, and tracking changes in stock market trends over time.
Create a Lag Function in Excel (With Examples)
Often you may want to calculate lagged values in Excel. Fortunately this is easy to do use the OFFSET() function.
The following examples show how to use the OFFSET() function in practice.
Example 1: Calculate Lagged Values in Excel
Suppose we have the following dataset in Excel that shows the total sales made by some store in 10 consecutive days:

We can use the following formula to calculate the lagged sales values in a new column:
=OFFSET(B3, -1, 0)
We can type this formula into cell C3 and drag it down to every remaining cell in column C:

The “Lag Sales” column shows the sales for a lag of n=1.
For example, on day 2 the store made 19 sales. The lagged value of sales on day 2 (e.g. the sales made on day 1) is 13 sales.
Example 2: Calculate Lagged Values by Group in Excel
Suppose we have the following dataset in Excel that shows the total sales made by two different stores during 5 days each:

We can use the following formula to calculate the lagged sales values by store in a new column:
=IF(A3=A2, OFFSET(B3, -1, 0), "")
We can type this formula into cell C3 and drag it down to every remaining cell in column C:

This function first checks if the store value in the current row is equal to the store value in the previous row.
If it is, then it returns the lagged sales value. If it’s not, then it returns a blank.
For example, in row 3 the sales value was 19. Since the store value in row 2 is equal to row 3, the lagged value of sales is calculated as 13.
However, in row 7 the value for store does not match the value for store in row 6, so a blank value is returned instead of a lagged sales value.
Additional Resources
The following tutorials explain how to perform other common tasks in Excel:
Cite this article
stats writer (2024). “How can I create a lag function in Excel, and what are some examples of its use?”. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-create-a-lag-function-in-excel-and-what-are-some-examples-of-its-use/
stats writer. "“How can I create a lag function in Excel, and what are some examples of its use?”." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-create-a-lag-function-in-excel-and-what-are-some-examples-of-its-use/.
stats writer. "“How can I create a lag function in Excel, and what are some examples of its use?”." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-create-a-lag-function-in-excel-and-what-are-some-examples-of-its-use/.
stats writer (2024) '“How can I create a lag function in Excel, and what are some examples of its use?”', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-create-a-lag-function-in-excel-and-what-are-some-examples-of-its-use/.
[1] stats writer, "“How can I create a lag function in Excel, and what are some examples of its use?”," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.
stats writer. “How can I create a lag function in Excel, and what are some examples of its use?”. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
