Calculate a Year-to-Date Total by Period in Excel
Question details
Calculate a year-to-date total through the period number entered in cell A2.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Period values are arranged across a row, and the user wants the total to update when the selected period changes.
- Observed behavior
- The desired total includes period 1 through the period specified in A2.
Arrange the 12 period values in chronological order across C5:N5. Enter a whole number from 1 through 12 in A2, and choose an output cell outside C5:N5.
Use SUM and INDEX to total through the selected period
Use this formula when period values are in consecutive columns and A2 contains the ending period number.
INDEX selects the ending cell within C5:N5, and SUM adds the values from C5 through that cell.
Select A2 and enter a whole number from 1 through 12.
Select an empty cell outside C5:N5, such as O5, and enter =SUM(C5:INDEX(C5:N5,1,A2)).
Press Enter. With 1 in A2, the formula totals C5; with 4 in A2, it totals C5:F5.

Calculate year-to-date totals in WPS Spreadsheets
Use the same SUM and INDEX formula in WPS Spreadsheets to total consecutive periods through the number selected in A2.
- 1. Open your spreadsheet: Open WPS Spreadsheets and use Open to select your workbook.
- 2. Set up the periods: Place the period values in C5:N5 and enter a period number from 1 through 12 in A2.
- 3. Add the formula: Select O5 or another empty cell outside the period range and enter =SUM(C5:INDEX(C5:N5,1,A2)).
- 4. Calculate and save: Press Enter to calculate the total, then use File > Save to save the workbook.

Frequently Asked Questions
How does the formula know which period to stop at?
INDEX(C5:N5,1,A2) selects the cell at the position specified in A2. SUM then totals the range from C5 through that cell.
What happens if I enter 4 in A2?
The formula totals C5:F5, covering periods 1 through 4.
Can I use a different range for the period values?
Yes. Replace C5:N5 with the consecutive cells containing your periods, and replace the first C5 with the first cell of that range. Enter a period number in A2 that does not exceed the number of columns.
Why does the formula return an error for my period number?
Check A2 and enter a whole number from 1 through 12 for the C5:N5 range. A number beyond the available columns can cause a reference error.




