Link to home
Start Free TrialLog in
Avatar of newparadigmz
newparadigmzFlag for United States of America

asked on

Excel Array formula Index/Match based on Max value

In attached, top table should match the values of bottom table.

I know I'm mostly right, but can't crack it.
QueryTable.xlsm
Avatar of barry houdini
barry houdini
Flag of United Kingdom of Great Britain and Northern Ireland image

I assume you can get the correct dates in columns O and P using your existing O18 formula copied across to P18 and down both columns. Once you have those try this formula in N18

=INDEX(otr!$A$3:$I$42,MATCH(1,($D$3:$D$42=$O18)*($A$3:$A$42=$M18),0),MATCH(otr!N$17,otr!$A$1:$I$1,0))

confirmed with CTRL+SHIFT+ENTER and copied down column

regards, barry
.......no actually I see you won't get the right results for column P, so you need this version for P18 copied down

=INDEX(otr!$A$3:$I$42,MATCH(MAX(IF($A$3:$A$42=$M18,$E$3:$E$42)),$E$3:$E$42,0),MATCH(otr!P$17,otr!$A$1:$I$1,0))

Note that if you take the max date for "Issue" and the max date for "Maturity" theoretically they might not belong to the same row. My suggested N18 formula just matches the max Issue date - if you want you can match both with this version

=INDEX(otr!$A$3:$I$42,MATCH(1,($D$3:$D$42=$O18)*($E$3:$E$42=$P18)*($A$3:$A$42=$M18),0),MATCH(otr!N$17,otr!$A$1:$I$1,0))

In this sample it gives you the same results as the previously suggested N18 formula, but depending on your data it may not do so (and may even return #N/A if there is no matching row).

regards, barry
newparadigmz,

The attached has two versions. The first (yellow) uses a helper column ("Row") to find the relevant row...
=OFFSET($A$1,$Q18-1,MATCH(N$17,$A$1:$I$1,0)-1)

Open in new window

...and the helper...
{=MIN(IF($A$3:$A$42&":"&$D$3:$D$42=$M18&":"&MAX(IF($A$3:$A$42=$M18,$D$3:$D$42)),ROW($A$3:$A$42),9^10))}

Open in new window

The second version (red) doesn't use a helper...
=OFFSET($A$1,MIN(IF($A$3:$A$42&":"&$D$3:$D$42=$M38&":"&MAX(IF($A$3:$A$42=$M38,$D$3:$D$42)),ROW($A$3:$A$42),9^10))-1,MATCH(N$17,$A$1:$I$1,0)-1)

Open in new window

Regards,
Brian.QueryTable-V2.xlsm
Avatar of newparadigmz

ASKER

@barry, you were right on the first count, only based off max of Issue, but you're not using max formula? also, when I apply it to other fields, getting circular reference errors.

@redmond, yours works consistently, but do you think it's possible to just use index/match/max combo, like what I was trying to attempt?
newparadigmz,

I'm sorry that mine wasn't what you wanted, but, trust me, it would be a complete waste of your time and mine to work on it while Barry's involved!

Regards,
brian.
ASKER CERTIFIED SOLUTION
Avatar of barry houdini
barry houdini
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
newparadimz,
Which version of Excel are you using?

If the answer is Excel 2010 or later, then you can use the AGGREGATE function. It will let you create a formula that has the benefits of Boolean expressions without needing to be array-entered. Here is a formula for P18 that you may copy both across and down:
=AGGREGATE(14,6,INDEX(otr!$A$3:$I$42,,MATCH(P$17,otr!$A$1:$I$1,0))/(otr!$A$3:$A$42=$M18),1)

The first parameter (14) means to find the largest values. The last parameter (1) means to find the first largest value. The combination is equivalent to MAX. The second parameter (6) means to ignore error values (the Boolean expression returns an error value if no match in column A for M18).

Brad
@ barry, yes!, last formula works perfect!
The circular reference was because formula should look in the main data table, and copied across, so when I put it in O18, it referenced itself.
While I don't fully understand the Match nesting, I can 'see' that it is acting on the max of Issue date and lookup value.

@ red, yours also works perfect, just less intuitive for me to understand.

@ byundt, thanks, using 2007, but good to know!