Function Problems

How to Average Positive Values in Every Fifth Row in Excel

Elise WilliamsElise Williams Oct 16, 2026 869 views

Question details

The user needs a formula to calculate the average of only the positive numbers (greater than zero) that appear at a specific interval, such as every fifth row in a dataset.

How to Average Positive Values in Every Fifth Row in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
Averaging data from a specific periodic row pattern (e.g., E22, E27, E32) while ensuring that any zero or negative values within those specific cells are excluded from the final calculation.
Observed behavior
The standard AVERAGEIF function returns an error or incorrect result because it cannot directly process noncontiguous cell patterns or evaluate isolated rows based on intervals.
Before you start

Verify the starting row number of your dataset, as you will need it to correctly set the mathematical offset in the MOD function to target the right interval.

Solution 1Recommended

Use SUMPRODUCT and MOD Formulas

This is the most efficient method to dynamically identify every fifth row and calculate the average specifically for cells that contain positive values.

Because AVERAGEIF does not support array transformations or noncontiguous ranges natively, we combine SUMPRODUCT, MOD, and ROW to build a custom array logic. The first SUMPRODUCT calculates the total sum of the positive values in every fifth row, and the second SUMPRODUCT counts how many such values exist to find the average.

1
Select the output cell

Click on the empty cell in your worksheet where you want the final average result to be displayed.

2
Enter the array formula

Type the following formula into the formula bar: =SUMPRODUCT((MOD(ROW(E22:E82)-1,5)=1)*E22:E82)/SUMPRODUCT((MOD(ROW(E22:E82)-1,5)=1)*(E22:E82>0)). Modify the range E22:E82 to match your specific data limits.

3
Execute the calculation

Press Enter to apply the formula. The cell will now display the average of values greater than zero for every fifth row.

Use SUMPRODUCT and MOD Formulas
Adjusting the Row Offset: The '-1' and '5' in the MOD function control the interval. If your data starts on a different row, you may need to tweak the '-1' offset so that the MOD calculation for your first target row equals 1.
Manage Complex Formulas in WPS Spreadsheet

Easily Calculate Advanced Averages with WPS Spreadsheet

WPS Spreadsheet provides full support for complex array formulas like SUMPRODUCT and MOD, making it incredibly easy to process noncontiguous data and periodic row calculations without complex workarounds.

  1. 1. Open your file in WPS: Launch WPS Office and open your spreadsheet file containing the data you need to average.
  2. 2. Select the target cell: Click the cell where the final average result should be displayed.
  3. 3. Enter the formula: Paste the SUMPRODUCT and MOD array formula into the top formula bar.
  4. 4. Calculate the result: Press Enter to instantly evaluate the specific intervals and extract the average of the positive values.
Fully compatible with Microsoft Excel formulas, including array functions like SUMPRODUCT and AVERAGEIFSProcesses complex data ranges and noncontiguous data smoothly and accuratelyFree to use with a familiar, user-friendly interface that requires no learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why does AVERAGEIF return a #VALUE! error when selecting multiple single cells?

The AVERAGEIF function requires a single, continuous range of cells (like A1:A10) to evaluate its criteria. It cannot process a union of separate, noncontiguous cells (like E22, E27, E32), which triggers a #VALUE! error. Array formulas or helper columns are needed as a workaround.

How do I modify the formula to average every third row instead of every fifth?

In the formula MOD(ROW(E22:E82)-1, 5), change the divisor '5' to '3'. You must also adjust the offset '-1' depending on the starting row, ensuring that the calculation MOD(RowNumber - Offset, 3) equals 1 for your first target row.

Does the SUBTOTAL function ignore hidden rows when calculating averages?

Yes. If you use the function argument 1 (for AVERAGE) with an AutoFilter, it ignores rows hidden by the filter. If you manually hide rows by right-clicking and selecting 'Hide', you must use the argument 101 (e.g., =SUBTOTAL(101, range)) to ensure manually hidden rows are also excluded.