Get last 2 non blank values of a row

Dani_LobP

Board Regular
Joined
Aug 16, 2019
Messages
134
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to make a column to obtain last values that were added in some table. Each month table expands so new values are added...

So far, I managed to get the way to obtain last value, last value -1 and last value -2 (so I'm having last 3 values in other words).

My problem comes when the last values happen to have same value. then formula seems that cant read it as 2 separate items and ignores it.
And for some reason not always reads correctly values.

Below example table (I actually work with values than can be also text, or %, not just numbers, but I assume formula would work same regardless the cell format).

Last value minus2Last value minus 1Last valueJanFebMarAprMayJunJulAugSepOctNovDec
#VALUE!#SPILL!112421
#SPILL!0101121
1351355
#VALUE!#SPILL!22412
#VALUE!#SPILL!22322
1121112

A2 formula: =INDEX(D2:O2,MATCH(LOOKUP(2,1/(D2:O2<>""),D2:O2),D2:O2,0)-2)
B2 formula: =INDEX(D2:O2,MATCH(LOOKUP(2,1/(D2:O2<>""),D2:O2),D2:O2,0)-1)
C2 formula: =IFNA(LOOKUP(2,1/(D2:O2<>""),D2:O2),"")

Thanks in advance!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
This cheats slightly but will work how you have it setup there. In A2:

=LOOKUP(2,1/($D2:$O2<>""),B2:M2)

Drag across and down.
 
Upvote 0
Book1
ABCDEFGHIJKLMNO
1Last value minus2Last value minus 1Last valueJanFebMarAprMayJunJulAugSepOctNovDec
242112421
312101121
43551355
54122412
63222322
71121112
Sheet6
Cell Formulas
RangeFormula
A2:C7A2=INDEX($D2:$O2,AGGREGATE(14,6,(COLUMN($D2:$O2)-3)/($D2:$O2<>""),4-COLUMN()))
 
Upvote 0
Book1
ABCDEFGHIJKLMNO
1Last value minus2Last value minus 1Last valueJanFebMarAprMayJunJulAugSepOctNovDec
242112421
312101121
43551355
54122412
63222322
71121112
Sheet6
Cell Formulas
RangeFormula
A2:C7A2=INDEX($D2:$O2,AGGREGATE(14,6,(COLUMN($D2:$O2)-3)/($D2:$O2<>""),4-COLUMN()))
Thanks, this seems to work as I want :D
 
Upvote 0
Book1
ABCDEFGHIJKLMNO
1Last value minus2Last value minus 1Last valueJanFebMarAprMayJunJulAugSepOctNovDec
242112421
312101121
43551355
54122412
63222322
71121112
Sheet6
Cell Formulas
RangeFormula
A2:C7A2=INDEX($D2:$O2,AGGREGATE(14,6,(COLUMN($D2:$O2)-3)/($D2:$O2<>""),4-COLUMN()))
Actually, i just noticed that it won't work in the case that there is a formula in the cell.

All the empty cells in the row, have this formula: =IF(Template!B3="","",Template!B3) , so wherever you see empty cell in the columns, actually there is a formula, and when the original table is populated, then the value will be displayed here.

So the formula you helped with, works, in the case there is nothing in the cell, that's why I had the condition of being cell other than "" .
Somewhere in your formula should be able to add IF(D2:O2<>"") maybe? , as I had in my example. Im trying to play with that, but so far no luck :D

Makes sense what I mentioned? thanks.
 
Upvote 0
In my mini sheet, cells with red triangle comment, are formula : = ""
cell is blank, or cell with fornula that generate "", that's no matter , with my formula.
If its your matter, could you post your sheet, with error ?


Book1
ABCDEFGHIJKLMNO
1Last value minus2Last value minus 1Last valueJanFebMarAprMayJunJulAugSepOctNovDec
221512421 5
312101 21
43551355 
54122412
63222322
71121112
Sheet2
Cell Formulas
RangeFormula
A2:C7A2=INDEX($D2:$O2,AGGREGATE(14,6,(COLUMN($D2:$O2)-3)/($D2:$O2<>""),4-COLUMN()))
I2,I4,F3I2=""
 
Upvote 0
In my mini sheet, cells with red triangle comment, are formula : = ""
cell is blank, or cell with fornula that generate "", that's no matter , with my formula.
If its your matter, could you post your sheet, with error ?


Book1
ABCDEFGHIJKLMNO
1Last value minus2Last value minus 1Last valueJanFebMarAprMayJunJulAugSepOctNovDec
221512421 5
312101 21
43551355 
54122412
63222322
71121112
Sheet2
Cell Formulas
RangeFormula
A2:C7A2=INDEX($D2:$O2,AGGREGATE(14,6,(COLUMN($D2:$O2)-3)/($D2:$O2<>""),4-COLUMN()))
I2,I4,F3I2=""

I actually have my columns from W to AK ... Data for Feb is actually in W3, and last column would be AK3.
I am unsure if that would be any reason for formula to not adapt if I modify the D2:O2 into W3:AK3 ...

I get some #Num! error when i do so.

1653387139193.png


Hopefully this helps. thanks!
 
Upvote 0
Have you tried the formula from Steve in post#2?
 
Upvote 0
Yes, but only issue I see is when the data is missing and only have 2 values, in that case it seems to be repeating again one.
Ideally should be displaying some error or Not applicable or something. have a number could lead to confusion.

1653390683887.png


apart from that, seems to be working good.
 
Upvote 0
Yes, but only issue I see is when the data is missing and only have 2 values, in that case it seems to be repeating again one.
Ideally should be displaying some error or Not applicable or something. have a number could lead to confusion.

View attachment 65414

apart from that, seems to be working good.
Trying to see if this would fix/solve the case: =IF(LOOKUP(2,1/($W3:$AK3<>""),U3:AK3)=V3,"",LOOKUP(2,1/($W3:$AK3<>""),U3:AK3))

But not sure if can really use it since in the case as per below, when for some reason numbers are same, would show as empty..

1653390888147.png
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
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