How to Average Last N Values in Multiple Columns

In Excel there are a lot of built-in functions, and AVERAGE is one of the most frequently used functions. In daily work, we may apply AVERAGE function together with some other functions to get average based on some conditions. In this article, we will let you know the method to apply AVERAGE function together with OFFSET function and COUNT function to get the average of last N values in multiple columns.

In this article, we will introduce you the syntax, arguments, and basic usage of above three functions. We will also explain how the formula works with these functions.

EXAMPLE

Average Last N Values in Multiple Columns 1

In this case, we want to calculate the average of last 3 numbers in Row2. The most simple way, we can directly create formula “=AVERAGE(C2:E2)” to get the average as we are already clear that the last values are from range C2:E2. If we want to create a general formula that can cover “returns the average of last N value from multiple columns”, obviously the simple formula with only AVERAGE function cannot meet our demands.

To get the average of last N values for a dynamic range with multiple columns, we can apply AVERAGE function together with other functions to help us. In this article, we also apply OFFSET function together with COUNT function to help us.

FORMULA with AVERAGE & OFFSET & COUNT FUNCTIONS

In E2, enter the formula =AVERAGE(OFFSET(A2,0,COUNT(A2:E2)-3,1,3)), then press Enter, average of last three numbers is 40.

Average Last N Values in Multiple Columns 2

(20+60+40)/3=40, the formula works correctly.

FUNCTION INTRODUCTION

AVERAGE function returns the average of numbers from a given range reference.

Syntax:

=AVERAGE(number1, [number2], …)

Usage:

Average Last N Values in Multiple Columns 3

OFFSET returns a number or a dynamic range based on given five parameters: starting point, row offset, column offset, height in rows and width in rows.

Syntax:

=OFFSET(reference, rows, cols, [height], [width])

Usage 1:

Average Last N Values in Multiple Columns 4

Reference: A1, it is the starting point

Rows: 3, 3 rows below the starting point

Cols: 2, 2 columns to offset to the right of the starting point

Height & Width: optional, no value

Usage 2:

Average Last N Values in Multiple Columns 4

Reference: A1, it is the starting point

Rows: 3, 3 rows below the starting point

Cols: 2, 2 columns to offset to the right of the starting point

Height: 2, it is used together with width, determine the size of the returned range reference, in this case is 2*2 (two rows*two columns)

Width: 2, it is used together with height, determine the size of the returned range reference, in this case is 2*2 (two rows*two columns)

 

COUNT returns the count of numbers from a given range.

Syntax:

=COUNT(value1, [value2], …)

Usage:

Average Last N Values in Multiple Columns 10

EXPLANATION

=AVERAGE(OFFSET(A2,0,COUNT(A2:E2)-3,1,3))

In this case, COUNT(A2:E2) returns 5, there are five cells with numbers in range reference A2:E2.

Average Last N Values in Multiple Columns 10

For OFFSET function in this case, the five inputs are:

Reference: A2. It is the starting point in row2.

Rows: 0. That means 0 row below the starting point. It determines the returned range reference is started in row2.

Cols: (COUNT(A2:E2)-3). Returned value is 2, that means 2 columns to offset to the starting point.

Based on above “Reference”, “Rows” and “Cols”, we can confirm the returned range is still stayed in row2, and two columns to offset to A2, so the first column for this range is C column, and the starting cell is C2.

Let’s verify if out thought is correct. Enter =OFFSET(A2,0,2) in B7, then press Enter, formula returns C2 value 20, see screenshot below.

Average Last N Values in Multiple Columns 10

Height: 1. It determines that the returned range is 1-row in height. We stayed in row2 as there is only 1-row in height.

Width: 3. It determines that the returned range is 3-columns in width. From C2, the returned range is expanded from C column to E column, total 3 columns.

 Based on above “Height” and “Width”, we can confirm the returned range is C2:E2. Enter =OFFSET(A2,0,2,1,3) into B6. As it is an array formula, so press Ctrl+Shift+Enter to get result.

Average Last N Values in Multiple Columns 10

Select {=OFFSET(A2,0,2,1,3)} in formula bar and press F9, {20,60,40} is displayed. {20,60,40} are the values in C2:E2.

Average Last N Values in Multiple Columns 10

Now, =AVERAGE(OFFSET(A2,0,COUNT(A2:E2)-3,1,3)) is equal to =AVERAGE(C2:E2).

Let’s see how the formula works step by step:

Step 1: Average Last N Values in Multiple Columns 11

Step 2: Average Last N Values in Multiple Columns 13

Step 3: Average Last N Values in Multiple Columns 13

Step 4: Average Last N Values in Multiple Columns 14

Above all, to get average from last N number in multiple columns, we can use below formula:

=AVERAGE(OFFSET(Starting Point,0,COUNT(Range)-N,1,N))

SUMMARY

1. AVERAGE function is used for returning the average of some numbers from a given range in Excel.

2. OFFSET function returns a number or a dynamic range based on given five inputs. Actually, rows, cols, height and width can be input negative numbers.

3. COUNT function only returns count of numbers.

Related Functions


  • Excel AVERAGE function
    The Excel AVERAGE function returns the average of the numbers that you provided.The syntax of the AVERAGE function is as below:=AVERAGE (number1,[number2],…)….
  • Excel COUNT function
    The Excel COUNT function counts the number of cells that contain numbers, and counts numbers within the list of arguments. It returns a numeric value that indicate the number of cells that contain numbers in a range…

 

 

Related Posts

Calculate Grades With VLookup in Excel

Why Should You Calculate Grades With VLookup Excel? If you're looking for a simple way to find out a student's grades, VLOOKUP Excel can do the trick. This function uses a lookup table to find the values and sort them ...

Repeating Character n Times in Excel

In daily life, we can use repeated characters to indicate the magnitude or priority of something. For example, a single “!” indicates a minor case, double “!!” indicates a medium case, and triple “!!!” indicates a high case, and so ...

Calculate Cumulative Loan Interest in Excel

What is Cumulative Loan Interest? When comparing different types of loans, many people want to know what is Cumulative Loan Interest. The sum of all interest payments you've made on a loan is referred to as cumulative interest. Different lenders ...

Calculate Cumulative Loan Principal Payments in Excel

How do you Calculate Cumulative Loan Principal Payments in Excel? There are a few different ways to calculate this information, but one way has been proven to be accurate more often than others. One option is to use the CUMPRINC ...

Trap Error or Replace Error by Specific Value with IFERROR function

We often use Excel formulas in our work life, and we may encounter this situation that the formula throws an error and finally an error like #DIV/0! Is displayed in the cell. In today’s tutorial, we will introduce you the ...

Sidebar