How to retrieve the last 5 rows of a Pivot Table using a Dynamic Range

rca

Board Regular
Joined
Mar 1, 2005
Messages
182
I have the following data in a Pivot Table in column C:

Value
10
20
30
40
50
60
70
80
90
100
Grand Total: 550

I would like to create a dynamic range that references only the last 5 records of the Pivot Table: 60, 70, 80, 90, 100.

The formula I'm using is:

=OFFSET($C$2,COUNT($C:$C),0,-5,1)

Unfortunately, this formula references the grand total row. Is there a way to amend the formula such that it only references the 5 rows directly above the grand total row? Thanks!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try
Code:
=OFFSET(C2,COUNT(C:C)-2,0,-5,1)
 
Upvote 0
I believe this formula will work if there are no blank cells. What if the data were as follows?

Value
10
20
30
40
50
60

80

100
Grand Total: 390

Is there a way to treat blank cells?
 
Upvote 0
Try
Code:
=OFFSET(C2,COUNT(C:C)-2+COUNTIF(C2:INDEX(C:C,MATCH(999999999999999,C:C)),""),0,-5-COUNTIF(C2:INDEX(C:C,MATCH(999999999999999,C:C)),""),1)


If you want to remove the zero(blank cells) form the array
Code:
=AGGREGATE(14,6,OFFSET($C$2,COUNT(C:C)-2+COUNTIF($C$2:INDEX(C:C,MATCH(999999999999,C:C)),""),0,-5-COUNTIF($C$2:INDEX(C:C,MATCH(999999999999,C:C)),""),1),ROW(INDIRECT("1:"&SUM(--(OFFSET($C$2,COUNT(C:C)-2+COUNTIF($C$2:INDEX(C:C,MATCH(999999999999,C:C)),""),0,-5-COUNTIF($C$2:INDEX(C:C,MATCH(999999999999,C:C)),""),1)<>0)))))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,089
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top