Function Problems

How to Compare Excel Rows with Previous Values Using SCAN

Tauseeq MagsiTauseeq Magsi Nov 11, 2026 869 views

Question details

The user needs a way to evaluate and compare values in current Excel rows against previous rows using dynamic array functions (SCAN, VSTACK, DROP, MAP) to identify new maximum values and compute running totals.

How to Compare Excel Rows with Previous Values Using SCAN and VSTACK
Product
Excel
Device & OS
not provided
Scenario
Identifying new maximum values dynamically or calculating running commission totals without relying on traditional drag-down cell formulas.
Observed behavior
By manipulating arrays—specifically shifting an array down by adding a zero at the top and removing the last row—users can force Excel to compare a row's current value directly with the previous row's running result.
Before you start

Ensure you are using a modern spreadsheet environment (such as Microsoft 365 or the latest WPS Office) that supports dynamic array functions, as older versions do not include SCAN, VSTACK, or DROP.

Solution 1Recommended

Use SCAN, VSTACK, and DROP to Identify New Maximums

This is the recommended method for creating a running calculation and comparing it against the previous row's value using an array offset.

The core concept relies on array cloning and shifting. First, you calculate a running maximum using the SCAN function. Then, you shift that newly created array down by one position using VSTACK (to put a 0 at the top) and DROP (to remove the final excess row). This aligns the previous row's maximum with the current row, allowing a direct mathematical comparison inside an HSTACK.

1
Select the destination cell

Click on an empty cell where you want the dynamic array result to spill. Ensure there is enough empty space below it to accommodate the entire dataset length.

2
Input the LET formula

Type the formula: =LET(currentMax, SCAN(0, currentValue, MAX), priorMax, DROP(VSTACK(0, currentMax), -1), isNewMax, currentMax>priorMax, HSTACK(currentMax, IF(isNewMax, "New Max!", "Same old")))

3
Update the named range

Replace 'currentValue' in the formula with your actual data range (e.g., A2:A20).

4
Execute the dynamic array

Press Enter. The formula will automatically spill down the column, outputting both the running maximum and a text label indicating if a new maximum was reached.

Use SCAN, VSTACK, and DROP to Identify New Maximums
The Array Shift Trick: The combination of DROP(VSTACK(0, array), -1) is a brilliant standard workaround in dynamic arrays. It perfectly offsets the data by one row, removing the need for traditional relative row references.
Advanced Formula Support

Easily Manage Dynamic Arrays with WPS Office

WPS Spreadsheet provides comprehensive support for modern dynamic array functions. You can easily build complex formulas using SCAN, VSTACK, DROP, and LET to completely automate your data analysis without traditional drag-down limits.

  1. 1. Download and Install: Download WPS Office Free, install it on your device, and open your existing Excel workbook.
  2. 2. Enter Array Formulas: Select any empty cell, type your LET, SCAN, or VSTACK formulas exactly as you would in modern Excel.
  3. 3. Enjoy Automatic Spilling: Press Enter, and WPS Spreadsheet will automatically execute the array logic, spilling the results into adjacent cells instantly.
Fully compatible with Microsoft Excel's modern dynamic array formulas.Built-in syntax highlighting to help you read and debug complex LET and LAMBDA setups.Lightweight application with blazing fast calculation speeds for large array datasets.Free to use with a familiar, easy-to-navigate interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my SCAN function return a #NAME? error?

This usually happens if your spreadsheet software is not updated. SCAN, VSTACK, and DROP are modern dynamic array functions. Ensure you are using Microsoft 365, Excel 2021, or the latest version of WPS Office.

How do VSTACK and DROP help compare previous rows?

By stacking a zero or blank value at the top of an array using VSTACK, and then dropping the last row using DROP(-1), you effectively push all values down by one row. This creates a 'previous value' array that aligns perfectly with your original array for easy row-by-row comparison.

Can I use this dynamic array approach for calculating running inventory?

Yes. By replacing the MAX logic inside the SCAN function with a cumulative sum or subtraction, you can track running inventory totals and seamlessly compare current stock levels with previous rows.

Do I need to copy or drag the formula down the column?

No. Because these are dynamic array functions, you only need to enter the formula in the top-left cell of your destination range. The results will automatically 'spill' down the column to exactly match the dimensions of your input data.