Share via

What formula can I use in Excel to sum/average the last 2 values in a column if there are gaps in the data?

Anonymous
2024-01-08T15:38:04+00:00

Hi,

I have the formula to calculate the sum and average of the last 2 values in Column A if there are no gaps in the data. This works if I add further values into the column.

Formula under 'Sum': =SUM(OFFSET(A1,COUNT(A1:A17)-2,0,2))

Formula under 'Average': =AVERAGE(OFFSET(A1,COUNT(A1:A17)-2,0,2))

1.00 Sum Average
2.00 Last 2 values 9.00 4.50
3.00
4.00
5.00

However, when there are gaps in the data, the above formulae do not work in calculating the sum/average of the last 2 values in the Column:

1.00 Sum Average
2.00 Last 2 values 5.00 5.00
3.00
4.00
5.00
7.00

As you can see, the sum should be 5+7=12 and the average should be of 5 and 7 (6),

Is there a formula I can use which would automatically discount blank cells?

Thank you!

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
  1. HansV 462.6K Reputation points MVP Volunteer Moderator
    2024-01-08T16:00:02+00:00

    If you have Microsoft 365 or use Excel Online:

    =AVERAGE(TAKE(FILTER(A1:A17, A1:A17<>""),-2))

    1 person found this answer helpful.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Ashish Mathur 101.8K Reputation points Volunteer Moderator
    2024-01-08T23:22:28+00:00

    Hi,

    In cell E2, enter this formula and drag down

    =SUM(TAKE(TOCOL(A1:A7,1),-2))

    In cell F2, enter this formula and drag down

    =AVERAGE(TAKE(TOCOL(A1:A7,1),-2))

    Hope this helps.

    0 comments No comments
  2. Anonymous
    2024-01-08T17:08:40+00:00

    Thank you so much!

    0 comments No comments
  3. Anonymous
    2024-01-08T16:00:46+00:00

    If you are using M365.

    =SUM(A:A)-SUM(TAKE(FILTER(A:A,A:A<>""),COUNT(A:A)-2))

    Or

    =INDEX(FILTER(A:A,A:A<>""),COUNT(A:A))+INDEX(FILTER(A:A,A:A<>""),COUNT(A:A)-1)

    For average, you may directly divide 2 from the sum value.

    0 comments No comments