Sum a Selected Month and the Previous Two Months in Excel
Question details
Calculate the total for a selected month and the two preceding months, with appropriate handling when earlier months are unavailable.

- 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.
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.
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.
Enter a month in E1 that exactly matches an entry in B2:B13.
Select E2 and enter =SUM(INDEX(C2:C13,MAX(1,MATCH(E1,B2:B13,0)-2)):INDEX(C2:C13,MATCH(E1,B2:B13,0))).
Press Enter. E2 sums the selected row and up to two preceding rows in C2:C13.

Require a Full Three-Month Total
Use this alternative when a partial total would be misleading.
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. Open your workbook: Open WPS Spreadsheet and use Open to select your Excel workbook.
- 2. Arrange the data: Place consecutive months in B2:B13 and their numeric values in C2:C13. Enter the selected month in E1.
- 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. Save the workbook: Use File > Save As to save the updated workbook in Excel format.

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.




