Index, Match, Max, If

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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:

xm3
ym3
xn3

<colgroup><col width="64" style="width:48pt" span="3"> </colgroup><tbody>
</tbody>
<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:

Row\Col
C​
2​
vad
3​
jad
4​
kad
5​
lad

Let's Stats house:

Row\Col
H​
I​
J​
2​
40​
x
3​
40​
y
4​
40​
z
5​
40​
w

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,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

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