Dynamic lookup (Index?) function

Occasional Contributor

Hello everyone,


my rows contain different KPIs and their values. The columns state the according month of the value entry per KPI (column B-M depict Jan22 to Dec22).


Via the LOOKUP function I was able to select the ongoing current value that was entered per row.


I'd like to know how I can calculate the current value (already foun it via lookup) minus the last value (the value before the current value).


Function as a question would be: What is the value before my latest entry in this row? (Excluding empty cells).


If that is only possible via VBA, pls provide the code and if possible one or two sentences with instructions.


Thank you all!

11 Replies


To provide a solution for this request, we're going to need to know what your vertical intersection looks like.  The months run left-to-right in columns.  Do you have numbers representing days of the month running vertical like this?



Also, if you're using LOOKUP, it suggests you might be on an older version of Excel. Which version do you have?


Excel version: Version 2202 Build 16.0.14931.20764 64 Bit

Somehow, I can't send a screenshot...


Vertical/rows: Different KPIs in the first column and the columns after are values regarding the KPI in the respective row and the date stated in the row above. So it is really just a calculation within one row.



According to your screenshot:


Imagine your days would be KPIs and I would like to know what the delta between your current value of KPI 17 and the value before the current (in this case629).


Remember it has to be dynamic due to the fact that there wont be forecasts so the latest value always equals the current value and there can be empty cells in a row if the KPI is tracked monthly, quarterly etc.



best response confirmed by sksk2424 (Occasional Contributor)


This may work for you:


Thank you so much @Patrick2788 


Works perfectly if there are no empty cells.


Can you think of a solution if for example the value 629 doesn't exist=empty cell?


The ideal return would therefore be: 35 - 845 = -810

Basically, ignoring the empty cell and going with the next lower entered value.


My current solution would be:



Unfortunately, I would need to extend the If clauses up to 11 blank cells because that is the maximum number of blank cells that could occur.


Is there a smarter way?


Thank you!


Try this one:

Thanks! I am suggling with the column "50" in SEQUENCE.

Which number is the 50 refering to? The total amount of columns in my range?
How do I determine this number?

The 50 is allowing for potentially 50 columns. FILTER removes the blanks and then the subtraction is done between Last value and Second last value. This formula would be a bit more elegant with access to functions like TAKE and DROP.



thank you for your reply!


Do you see something wrong with my function?




If I expand my selection for "range" and "c" a value returns. However, the value doesn't seem to be a calculation but more like an error within my formula.


Thanks in advance!!


The 50 is the problem. It may be best to pull the SEQUENCE number based on the rows in 'range':

Thank you!