Calculation Issues

Sum a Selected Month and the Previous Two Months in Excel

Ayan MasoodAyan Masood Dec 2, 2026 868 views

Question details

Calculate the total for a selected month and the two preceding months, with appropriate handling when earlier months are unavailable.

Sum a Selected Month and the Previous Two Months in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet lists months in a lookup column and their values in an adjacent column. The user selects a month to calculate a rolling total.
Observed behavior
The desired result is a sum of the selected month's value and the values in the two preceding monthly rows.
Before you start

Arrange the months in chronological order with one row per month and no gaps. For the examples below, put unique month identifiers in B2:B13, their numeric values in C2:C13, and the selected month in E1.

Solution 1Recommended

Sum the Available Months with INDEX and MATCH

Use this formula to calculate up to three months, including a partial total for the first two rows.

1
Select the month

Enter a month in E1 that exactly matches an entry in B2:B13.

2
Enter the formula

Select E2 and enter =SUM(INDEX(C2:C13,MAX(1,MATCH(E1,B2:B13,0)-2)):INDEX(C2:C13,MATCH(E1,B2:B13,0))).

3
Check the result

Press Enter. E2 sums the selected row and up to two preceding rows in C2:C13.

Sum the Available Months with INDEX and MATCH
First two months: If the selected month is in the first row, the formula sums that row only. If it is in the second row, it sums the first two rows. Include earlier months in the lookup and value ranges if a full three-month total is needed across a year boundary.
Calculate in WPS Spreadsheet

Calculate a Rolling Three-Month Total in WPS Spreadsheet

Use INDEX and MATCH in WPS Spreadsheet to find a selected month and sum its value with up to two preceding months.

  1. 1. Open your workbook: Open WPS Spreadsheet and use Open to select your Excel workbook.
  2. 2. Arrange the data: Place consecutive months in B2:B13 and their numeric values in C2:C13. Enter the selected month in E1.
  3. 3. Calculate the total: Select E2, enter =SUM(INDEX(C2:C13,MAX(1,MATCH(E1,B2:B13,0)-2)):INDEX(C2:C13,MATCH(E1,B2:B13,0))), and press Enter.
  4. 4. Save the workbook: Use File > Save As to save the updated workbook in Excel format.
Calculate rolling monthly totals with familiar spreadsheet formulasOpen and edit Microsoft Excel XLSX and XLS filesUse a familiar spreadsheet interface for worksheet editingWork with a free, easy-to-use office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does the formula return #N/A?

MATCH returns #N/A when E1 does not exactly match an entry in B2:B13. Check the spelling or date value in E1 and make sure it matches the lookup column.

How can I include November and December when calculating January?

Add the prior year's November and December before January in chronological order, then expand both the month and value ranges in the formula to include those rows.

What happens if my month labels repeat each year?

MATCH finds the first matching label. Use unique month-and-year identifiers, such as monthly dates displayed as Jan 2025, and enter the matching date in E1.

Can I show a warning instead of a partial total for January or February?

Yes. Use the IF and MATCH formula in the full three-month solution. It displays "Not enough months" when fewer than two preceding rows are available.