Add Lag / Lead Column to Excel Files Online
Add a LAG or LEAD column to Excel files to shift any column forward or backward by N rows. See previous day's sales, next value in a sequence, or any time-shifted comparison — runs entirely in your browser.
How to add Lag / Lead Column to Excel files
- Drop your file onto the upload area. The first 200 rows are shown.
- Choose a Direction. LAG takes the value from an earlier row and names the new column prev_value. LEAD takes it from a later row and names it next_value.
- Pick the Value column and the Offset (rows), which defaults to 1. Set Order by to your date or sequence column so "previous" means what you expect.
- Optionally set Partition by so the shift restarts for each group, and a Default value for rows that have no earlier or later row. Rename the output column if you like.
- Click Add LAG Column (or Add LEAD Column), check the preview, then download the file.
Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.
Worked example
A hydrologist has daily temperature readings from two weather stations in one file and wants the previous day's reading next to each day, without mixing the stations.
Input (Excel)
Excel workbook, first sheet (Sheet1)
| station | reading_date | temp_c |
|---|---|---|
| WLG-01 | 2026-07-01 | 9.4 |
| AKL-02 | 2026-07-01 | 14.1 |
| WLG-01 | 2026-07-02 | 8.1 |
| AKL-02 | 2026-07-02 | 15.3 |
| WLG-01 | 2026-07-03 | 10.2 |
Settings
- Direction: LAG
- Value column: temp_c
- Offset: 1
- Order by: reading_date
- Partition by: station
- Default: (blank, NULL)
- Output column name: prev_value
Result
| station | reading_date | temp_c | prev_value |
|---|---|---|---|
| WLG-01 | 2026-07-01 | 9.4 | NULL |
| WLG-01 | 2026-07-02 | 8.1 | 9.4 |
| WLG-01 | 2026-07-03 | 10.2 | 8.1 |
| AKL-02 | 2026-07-01 | 14.1 | NULL |
| AKL-02 | 2026-07-02 | 15.3 | 14.1 |
Each station's first day has no earlier reading, so prev_value is NULL. The shift never crosses from one station to the other because of Partition by. The rows come back grouped by station, because that is how the window is computed. Sort by reading_date afterwards if you need the original interleaved order. A day-on-day change is then temp_c minus prev_value.
Working with Excel files
This is the equivalent of the common Excel formula =B3-B2 dragged down a column, except the tool also handles groups and does not break when rows are re-sorted. Only the first sheet is read. Date cells load from their stored date, so a column showing 7/2/26 arrives as 2026-07-02 and Order by follows the calendar. Dates typed as text still sort character by character, and 10/1/26 comes before 7/2/26. Run Parse Dates on those first.
Blank spacer rows between blocks of data count as real rows, so the row after a spacer gets an empty prev_value. Delete spacers first. If you type a Default value, it is converted to the value column's type. 0 works for a number column. A word like "none" does not work there and stops the run with a conversion error. The output is a new .xlsx on Sheet1. Dates are written as ISO text such as 2026-07-02.
Frequently Asked Questions
Is this the same as referencing the cell above in Excel?
For one sorted block of data, yes. The tool also restarts for each group with Partition by, orders by any column, and does not depend on the current sort of the sheet.
Why are dates in the downloaded Excel file text instead of dates?
Columns that loaded as dates are written as ISO text like 2026-07-02. Columns that loaded as text keep their original text. Use DATEVALUE in Excel to turn them back into date cells if needed.
What is the difference between LAG and LEAD?
LAG reads from N rows earlier, for example yesterday's value. LEAD reads from N rows later, for example the next appointment date. Both add one new column and leave the original rows in place.
What does the Default value do?
It fills rows that have no row N positions away, such as the first row of each partition for LAG. The value you type is converted to the value column's type. A number works for a numeric column, but text that is not a number causes a conversion error.
Why is Order by optional?
Without it the shift follows the order rows were loaded, which is often file order but is not guaranteed. Set Order by whenever row order matters, which is almost always.
Related Tools
Add Calculated Column to Excel Files Online
Add a new column to Excel files computed from an arithmetic expression over existing columns. No formulas, no code — just point and click.
Calculate Date Difference in Excel Files Online
Calculate the difference between two date or timestamp columns in Excel files directly in your browser. Output in days, months, years, hours, minutes, or seconds — no upload required.
Filter Excel Files Online
Filter rows in Excel files by column value, directly in your browser. Your data stays on your device.
Add Lag / Lead Column to CSV Files Online
Add a LAG or LEAD column to CSV files to shift any column forward or backward by N rows. See previous day's sales, next value in a sequence, or any time-shifted comparison — runs entirely in your browser.
Add Lag / Lead Column to Parquet Files Online
Add a LAG or LEAD column to Parquet files to shift any column forward or backward by N rows. See previous day's sales, next value in a sequence, or any time-shifted comparison — runs entirely in your browser.
Add Lag / Lead Column to JSON Files Online
Add a LAG or LEAD column to JSON files to shift any column forward or backward by N rows. See previous day's sales, next value in a sequence, or any time-shifted comparison — runs entirely in your browser.
Excel Viewer Online
View and inspect Excel files directly in your browser. Browse rows, check column names and data types — no upload required, your data stays on your device.
Convert Excel to Parquet Online
Convert Excel files to Parquet format directly in your browser. No upload required — your data never leaves your device.