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!
 
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.

what would be in the case that there is missing values in columns and just have 2? :) any "cheat" for that? :D
above shared screen and idea, but not fully working :D
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How about in T3 dragged down only
++Fluff.xlsm
TUVWXYZAAABACADAEAFAGAHAIAJAK
1FebMarAprMayJunJulAugSepOctNovDecJanFebMarApr
2
3 1212             
415101   5   10
5131415123456789101112131415
6 8   8           
Sheet4
Cell Formulas
RangeFormula
Y3:AK3,AA6:AK6,W6:Y6,AB4:AD4,X4:Z4Y3=""
T3:V6T3=LET(f,FILTER(W3:AK3,W3:AK3<>"",""),s,SEQUENCE(,3,COLUMNS(f)-2),IF(s<1,"",INDEX(f,s)))
Dynamic array formulas.
 
Upvote 0
How about in T3 dragged down only
++Fluff.xlsm
TUVWXYZAAABACADAEAFAGAHAIAJAK
1FebMarAprMayJunJulAugSepOctNovDecJanFebMarApr
2
3 1212             
415101   5   10
5131415123456789101112131415
6 8   8           
Sheet4
Cell Formulas
RangeFormula
Y3:AK3,AA6:AK6,W6:Y6,AB4:AD4,X4:Z4Y3=""
T3:V6T3=LET(f,FILTER(W3:AK3,W3:AK3<>"",""),s,SEQUENCE(,3,COLUMNS(f)-2),IF(s<1,"",INDEX(f,s)))
Dynamic array formulas.
that one seems to do the drill! thanks a lot!
ill keep testing and let you know if something. but looks good so far :)
 
Upvote 0
Hi,

Just found out some flaw in what i have built. Not sure where is supposed to be a mistake but i cant seem to see it.
I have the below table (example):
1654681336540.png


And from this table, i build the below:

1654681363758.png


For last values minus 1 and minus 2 i am using formula provided above (marked as solution and working great), and for the Month columns I am using the below (which happens to have some error:

Q3: =INDEX($W$1:$BG$1,MATCH(LOOKUP(2,1/(W3:BG3<>""),$W$1:$BG$1),$W$1$BG$1,0)-1)
R3: =INDEX($W$1:$BG$1,MATCH(LOOKUP(2,1/(W3:BG3<>""),$W$1:$BG$1),$W$1:$BG$1,0)-2)
S3: =INDEX($W$1:$BG$1,MATCH(LOOKUP(2,1/(W3:BG3<>""),$W$1:$BG$1),$W$1:$BG$1,0))

As you can see in pic2, it should not be displaying JUL1 (Q) and JUN (R), but MAY (Q) and APR (R) ... since is where next values are.

Thanks in advance.
 
Upvote 0
How about
Excel Formula:
=LET(f,FILTER(W$1:BG$1,W3:BG3<>"",""),s,SEQUENCE(,3,COLUMNS(f)-2),IF(s<1,"",INDEX(f,s)))
 
Upvote 0
Solution
How about
Excel Formula:
=LET(f,FILTER(W$1:BG$1,W3:BG3<>"",""),s,SEQUENCE(,3,COLUMNS(f)-2),IF(s<1,"",INDEX(f,s)))
Thanks for your quick reply Fluff! as always very helpful.

If you happen to have some free time and feel like explaining this formula id be very grateful. Is already 2nd time i am using this one you shared and wonder if you can let know what each part of it is doing.
Either way, thanks a lot again!
 
Upvote 0
The filter function returns all the headers where row 3 is not blank & stores that in the variable f.
The sequence returns 3 numbers starting with the number of columns in f less 2 & the index then retunr those 3 column headers.
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

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