Index, Match, Max, If

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I'm using this array formula to return the max date where the primary key matches in 2 different worksheets, and it works fine.
{=MAX(IF(Specs!C:C='Info'!C2,Stats!H:H))}

I'm trying to get the value in column J on the Stats sheet, for the same line. I've been looking at this for a few hours. I've googled and googled, searched through this forum and 2 others. While I've found some information, I've not been able to tweak the formula to get the appropriate value. I want the formula to be dynamic if possible, because the data in the Stats sheet is dynamic.

I've tried these formulas, but none of them work:
{=INDEX(Specs!J:J,MAX(MATCH(Specs!C:C='Info'!C:C,Specs!H:H)))}
{=INDEX(Specs!J:J,MATCH(MAX(Specs!H:H),Specs!H:H,0))}
{=INDEX(Specs!J:J,MAX(MATCH(IF(Specs!C:C='Info'!C2,Specs!H:H),Specs!C:C,0)))}

The 2nd formula returns a number, but it's not associated with the correct record.

The end state goal is to enter the formula into the sheet via a macro, but I have to understand how the formula works first. Any help is appreciated.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You've got really close in the second one. Here is your formula:

{=INDEX(Stats!A:A,MATCH(MAX(IF(Specs!C:C=Info!C2,Stats!H:H)),Stats!H:H,0))}
 
Upvote 0
Control+shift+enter, not just enter:

=INDEX(Stats!J:J,MATCH(MAX(IF(Specs!C:C=Info!C2,Stats!H:H)),IF(Specs!C:C=Info!C2,Stats!H:H),0))

This gives you the J-value that corresponds to the first instance of the MAX value, not possible others. This means the following:

[TABLE="class: grid, width: 192"]
<colgroup><col width="64" style="width:48pt" span="3"> </colgroup><tbody>[TR]
[TD="width: 64, bgcolor: transparent"]x[/TD]
[TD="width: 64, bgcolor: transparent"]m[/TD]
[TD="width: 64, bgcolor: transparent, align: right"]3[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]y[/TD]
[TD="bgcolor: transparent"]m[/TD]
[TD="bgcolor: transparent, align: right"]3[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]x[/TD]
[TD="bgcolor: transparent"]n[/TD]
[TD="bgcolor: transparent, align: right"]3[/TD]
[/TR]
</tbody>[/TABLE]
<strike>
</strike>

The max value when B = m, correlates with x and y in A, not just with x.
 
Upvote 0
Thank you both for the reply!!! Aladin's formula seems to work the best. Now I get to try and nest some other formula in there! Woo hoo!
 
Upvote 0
Thank you both for the reply!!! Aladin's formula seems to work the best. Now I get to try and nest some other formula in there! Woo hoo!

Ah right my formula checks for column A. For J:

{=INDEX(Stats!J:J,MATCH(MAX(IF(Specs!C:C=Info!C2,Stats!H:H)),Stats!H:H,0))}

You don't have to use the colum referance for INDEX function in this scenario.
 
Last edited by a moderator:
Upvote 0
Ah right my formula checks for column A. For J:

{=INDEX(Stats!J:J,MATCH(MAX(IF(Specs!C:C=Info!C2,Stats!H:H)),Stats!H:H,0))}

You don't have to use the colum referance for INDEX function in this scenario.

Not good enough. It will potentially return a wrong J value.
 
Upvote 0

Let's Specs house:

[Table="width:, class:grid"][tr][td]Row\Col[/td][td]
C​
[/td][/tr][tr][td]
2​
[/td][td]vad[/td][/tr]
[tr][td]
3​
[/td][td]jad[/td][/tr]
[tr][td]
4​
[/td][td]kad[/td][/tr]
[tr][td]
5​
[/td][td]lad[/td][/tr]
[/table]


Let's Stats house:

[Table="width:, class:grid"][tr][td]Row\Col[/td][td]
H​
[/td][td]
I​
[/td][td]
J​
[/td][/tr][tr][td]
2​
[/td][td]
40​
[/td][td][/td][td]x[/td][/tr]
[tr][td]
3​
[/td][td]
40​
[/td][td][/td][td]y[/td][/tr]
[tr][td]
4​
[/td][td]
40​
[/td][td][/td][td]z[/td][/tr]
[tr][td]
5​
[/td][td]
40​
[/td][td][/td][td]w[/td][/tr]
[/table]


Let C2 of Info = jad

While:

=INDEX(Stats!J:J,MATCH(MAX(IF(Specs!C:C=Info!C2,Stats!H:H)),IF(Specs!C:C=Info!C2,Stats!H:H),0))

returns correctly y as result, the suggestion

=INDEX(Stats!J:J,MATCH(MAX(IF(Specs!C:C=Info!C2,Stats!H:H)),Stats!H:H,0))

must return x as result incorrectly for it underspecifies the match range.
 
Upvote 0
HI,
I have this, and it works fine so far...
=MAX(INDEX(LLN_Data[Reading], MATCH(1, ($M194=LLN_Data[Name]) * ("N/A"<>LLN_Data[Complete Time]), 0)))

LLN_Data[Reading are numbers
LLN_Data[Name is text
LLN_Data[Complete Time is date/time but may be as a text value
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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