Excel Formula Help - In Which Year did X Occur

Sundance_Kid

Board Regular
Joined
Sep 2, 2017
Messages
130
Office Version
  1. 365
Platform
  1. Windows
Hi,

See the below image, I want a formula to tell me in which year (most recent) was the last amount of Sales greater than 0. AS you can see for Product A that will have been 2021, but for Product B it will be 2024.

Is there some formula that can return the correct (most recent) year.

Thanks

Excel Formula Query_15.11.2023.png
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this

Book1
ABCDEFGHI
1
2201920202021202220232024
3500000002019
45005005000002021
Sheet1
Cell Formulas
RangeFormula
I3:I4I3=LOOKUP(2,1/(B3:G3>0),$B$2:$G$2)
 
Upvote 0
If you are not worried about users being on older versions of Excel then you can use XLookup (looking up last to first)
In I3
Excel Formula:
=XLOOKUP(TRUE,$B3:$G3>0,$B$2:$G$2,,0,-1)
 
Upvote 0
Solution
@SanjayGMusafir, interesting MAXIFS is not the first thing that came to my mind. A downside seems to be that if you convert the data set into an Excel Table, the year headings become text and the formula returns 0.
 
Upvote 0
Hi may I ask how the TRUE works within the Lookup value of the XLOOKUP please?
=XLOOKUP(TRUE,$B3:$G3>0,$B$2:$G$2,,0,-1)[/CODE]

Ignore I think I have it, the TRUE value is the TRUE from the lookup_array>0 ?
 
Last edited:
Upvote 0
Ignore I think I have it, the TRUE value is the TRUE from the lookup_array>0 ?
You are correct, if you highlight the lookup array (2nd parameter) and hit F9 you will see this:
Excel Formula:
=XLOOKUP(TRUE, {TRUE,TRUE,TRUE,FALSE,FALSE,FALSE}, $B$2:$G$2, , 0, -1)
the last parameter "-1" tells XLooup to look from right to left (last occurence)

Note: When you use more than one criteria they would be joined by a multiplication operator "*" (AND logic), this converts TRUEs to 1s and FALSE to 0s. If you do this your lookup value needs to be changed from being TRUE to 1.
eg you can force this with one criteria by adding "1*" or a double unary "--"
Rich (BB code):
=XLOOKUP(1, 1*($B3:$G3>0), $B$2:$G$2,,0,-1)
F9'd
Excel Formula:
=XLOOKUP(1, {1,1,1,0,0,0}, $B$2:$G$2,,0,-1)

This exceljet link may help.
 
Upvote 0
Hi Alex thank you for the very helpful/ detailed response, very much appreciated!

Through out all these years using excel I had always thought the lookup_value needed to be sourced from a location as such, found it quite smart how you came to that within the formula itself (probably the norm to most excel users on here but a great insight for me)

I'll be sure to go over the link you sent as well! Thanks once again.
 
Upvote 0

Forum statistics

Threads
1,215,530
Messages
6,125,347
Members
449,220
Latest member
Edwin_SVRZ

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