A Cleaner Way to Find Max Value?

dwgnome

Active Member
Joined
Dec 18, 2005
Messages
441
I am hoping to simplify the following formula that works as intended:

Code:
=MAX(INDEX((YEAR($B$7:$B$40)=$H$4)*$D$7:$D$40,0),INDEX((YEAR($B$7:$B$40)=$H$4-1)*$D$7:$D$40,0),(INDEX((YEAR($B$7:$B$40)=$H$4-2)*$D$7:$D$40,0)))

where H4 houses the number representing the year. The formula then finds the maximum value for the selected year and the rows that have the previous two years. So for example if H4 = 2013, then the formula seeks the maximum value in 2013, 2012 and 2011.

I tried =MAX(INDEX((YEAR($B$7:$B$40)=$H$4:$H$4-2)*$D$7:$D$40,0)), but that only got the maximum in the year 2011.

Thanks.

Excel 2003
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I am hoping to simplify the following formula that works as intended:

Code:
=MAX(INDEX((YEAR($B$7:$B$40)=$H$4)*$D$7:$D$40,0),INDEX((YEAR($B$7:$B$40)=$H$4-1)*$D$7:$D$40,0),(INDEX((YEAR($B$7:$B$40)=$H$4-2)*$D$7:$D$40,0)))

where H4 houses the number representing the year. The formula then finds the maximum value for the selected year and the rows that have the previous two years. So for example if H4 = 2013, then the formula seeks the maximum value in 2013, 2012 and 2011.

I tried =MAX(INDEX((YEAR($B$7:$B$40)=$H$4:$H$4-2)*$D$7:$D$40,0)), but that only got the maximum in the year 2011.

Thanks.

Excel 2003


Excel 2010
ABCDEF
4
5
62013
71/1/20003111
81/1/20015
91/1/20023
101/1/20034
111/1/20045
121/1/20053
131/1/200634
141/1/20074
151/1/20083
161/1/200943
171/1/20103
181/1/2011111
191/1/20124
201/1/201343
211/1/20142
221/1/20153
231/1/20163
Sheet1
Cell Formulas
RangeFormula
F7{=MAX(OFFSET(B7,MATCH(E6,YEAR($B$7:$B$40),0)-3,2,3))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Here is a different array-entered** formula for you to try...

=MAX(D7:D40*(YEAR(B7:B40)<=H4)*(YEAR(B7:B40)>=H4-2))

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.

NOTE: I assumed that your data could be laid out slightly differently than Robert did, so make sure you test both formulas out carefully against your actual data. Also note when testing that Robert placed the year in cell E6 instead of cell H4 as your original post indicated, so change his formula accordingly.
 
Last edited:
Upvote 0
Excel Workbook
BCDEFGH
1Dates______AmountsMax 3 years
2Jan 01, 2005500
3Jan 01, 2005400StartEndYear
4Oct 01, 201030001/01/1131/12/132013
5Jan 01, 2011200400
6Dec 01, 2012100400
7Dec 01, 20130
8Jun 01, 2013400
4b
Excel 2003
Cell Formulas
RangeFormula
F4=DATE(YEAR(End)-2,1,1)
H4=YEAR(End)
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Excel Workbook
NameRefers To
End='4b'!$G$4
rT=zList!$B$2:$D$10
Start='4b'!$F$4
Workbook Defined Names


two other alternatives
 
Upvote 0
Here is a different array-entered** formula for you to try...

=MAX(D7:D40*(YEAR(B7:B40)<=H4)*(YEAR(B7:B40)>=H4-2))

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.

NOTE: I assumed that your data could be laid out slightly differently than Robert did, so make sure you test both formulas out carefully against your actual data. Also note when testing that Robert placed the year in cell E6 instead of cell H4 as your original post indicated, so change his formula accordingly.
Here is a shorter array-entered** formula that works identically to the formula I posted above (hence, the note I posted there is still applicable)...

=MAX(D7:D40*(ABS(YEAR(B7:B40)-H4+1)<2))

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.
 
Upvote 0
HHV Missing Data - CA (2)

*BCD
7October 2011**
8November 2011143,717143,717
9December 2011134,689134,689
10January 201267,344*
11February 20120*
12March 20120*
13April 20120*
14May 20120*
15June 20120*
16July 20120*
17August 201267,565*
18September 2012135,130135,130
19October 2012134,943134,943
20November 2012130,049130,049
21December 2012133,660133,660
22January 2013130,677130,677
23February 2013131,358131,358
24March 2013132,038132,038
25April 2013132,719132,719
26May 2013133,400133,400
27June 2013127,955127,955
28July 2013128,635128,635
29August 2013129,316129,316
30September 2013129,997129,997
31October 2013130,827130,827
32November 2013131,582131,582
33December 2013132,338132,338
34January 2014**
35February 2014**
36March 2014**

<tbody>
</tbody>


HHV Missing Data - CA (2)

*J
20 * * * * 133,660
=MAX(OFFSET(B7,MATCH(H4,YEAR($B$7:$B$40),0)-3,2,3))

<tbody>
</tbody>


HHV Missing Data - CA (2)

*J
21
* * * * 133,660​
=MAX(D7:D40*(YEAR(B7:B40)<=H4)*(YEAR(B7:B40)>=H4-2))

<tbody>
</tbody>


Thank you Robert and Rick, I tried both formulas and it did not work as I don't think it is looking at all of the dates within 2013 and the two years prior (2012 and 2011); just three rows from what I can tell.

The maximum value selected should be 143,717.:eek:

Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0
You could try one or both of the suggestions that I provided.
Since your data starts at row 7, edit the ranges as required.
 
Upvote 0
Actually, my formula should be doing that (that was the difference between my formula and Robert's that I was trying to point out).

Two questions that you must answer...

1. You are showing two columns of values (Column C and Column D)... why? There was no mention of Column C in your original post... only Column D, so our formulas only return values for Column D values. Please clarify why you are showing Column C values along with Column D values now.

2. Also, I see you are showing asterisks mixed in with your numerical values... are they really there or did you use them as stand-ins for empty cells? If they are really there, I need to know because they will screw up the numerical calculations I am doing unless I change my formula to account for them.
 
Last edited:
Upvote 0
Thank you Dave, your approach worked well, but I was looking to just use the one date and using a more compact formula.

Rick, your revised solution worked perfectly and such a compact formula!:)

Column C is the "new" data based on a substitution algorithm (based on regulatory procedures for missing data), while column D is the actual data. You are seeing only a portion of the overall scheme in my real spreadsheet. The two year lookback that you helped me on is one of three data substitution methods based on the data capture rate.

The asterisks are not there, it somehow gets placed in the table when using Excel Jeanie.

Thanks everyone again for such great and fast responses, it really helped.:pray:
 
Upvote 0
I am guessing from your last post that you consider your question resolved... and that is good... but I am slightly worried for you. You said my first formula did not work correctly (although you did not say in what way it did not work correctly), but you said my second, shorter formula did work... I do not see how that is possible. Unless I am mistaken (and I am almost positive I am not), both those formulas should produce identical results, so I do not see how one worked and the other failed. What I am worried about is you ran them against different data samples so that the second formula did not get a chance to trip up on whatever made the first formula fail.
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,244
Members
448,879
Latest member
VanGirl

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