Formula for MAX value and lookup query?

deacon10

Board Regular
Joined
Aug 9, 2010
Messages
59
Office Version
  1. 365
Hi all,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Can any of you excel genius’s help? I have been struggling with what seemed at first like a very simple formula. I have the sample data as shown below and I am trying to work out a formula that provides the latest value in sheet 2 from sheet 1 column AF based on a number of conditions.<o:p></o:p>
<o:p></o:p>
If Sheet2 A1:A500 = Sheet1 F1:F500<o:p></o:p>
And Sheet1 G1:G500 = max & Sheet1 AF1:AF500 doesn’t = blank (i.e. last value in column AF)<o:p></o:p>
Then return adjacent value from Sheet1 AF1:AF500<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Sheet 1<o:p></o:p>
F-----G-----AF<o:p></o:p>
127--1-----15.6<o:p></o:p>
127--2------3.1<o:p></o:p>
128--1------2.0 <o:p></o:p>
128--2-----<o:p></o:p>
129--1------2.5<o:p></o:p>
129--2------1.6<o:p></o:p>
129--3------2.7<o:p></o:p>
130--1------3.3<o:p></o:p>
130--2------3.1<o:p></o:p>
130--3------1.6<o:p></o:p>
130--4------5.4<o:p></o:p>
130--5------<o:p></o:p>
130--6------

Sheet 2<o:p></o:p>
A--------B (desired results)<o:p></o:p>
127-----3.1<o:p></o:p>
128-----2.0<o:p></o:p>
129-----2.7<o:p></o:p>
130-----5.4
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Does anybody have any suggestions?<o:p></o:p>
<o:p></o:p>
Many many eternal thanks for any help<o:p></o:p>
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi all,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Can any of you excel genius’s help? I have been struggling with what seemed at first like a very simple formula. I have the sample data as shown below and I am trying to work out a formula that provides the latest value in sheet 2 from sheet 1 column AF based on a number of conditions.<o:p></o:p>
<o:p></o:p>
If Sheet2 A1:A500 = Sheet1 F1:F500<o:p></o:p>
And Sheet1 G1:G500 = max & Sheet1 AF1:AF500 doesn’t = blank (i.e. last value in column AF)<o:p></o:p>
Then return adjacent value from Sheet1 AF1:AF500<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Sheet 1<o:p></o:p>
F-----G-----AF<o:p></o:p>
127--1-----15.6<o:p></o:p>
127--2------3.1<o:p></o:p>
128--1------2.0 <o:p></o:p>
128--2-----<o:p></o:p>
129--1------2.5<o:p></o:p>
129--2------1.6<o:p></o:p>
129--3------2.7<o:p></o:p>
130--1------3.3<o:p></o:p>
130--2------3.1<o:p></o:p>
130--3------1.6<o:p></o:p>
130--4------5.4<o:p></o:p>
130--5------<o:p></o:p>
130--6------

Sheet 2<o:p></o:p>
A--------B (desired results)<o:p></o:p>
127-----3.1<o:p></o:p>
128-----2.0<o:p></o:p>
129-----2.7<o:p></o:p>
130-----5.4
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Does anybody have any suggestions?<o:p></o:p>
<o:p></o:p>
Many many eternal thanks for any help<o:p></o:p>
Sheet2

B1, control+shift+enter, not just enter, and copy down:
Rich (BB code):
=INDEX(Sheet1!$AF$1:$AF$500,MIN(IF(Sheet1!$F$1:$F$500=A1,
  IF(Sheet1!$G$1:$G$500=MAX(IF(Sheet1!$F$1:$F$500=A1,
   IF(ISNUMBER(Sheet1!$AF$1:$AF$500),Sheet1!$G$1:$G$500))),
    ROW(Sheet1!$AF$1:$AF$500)-ROW(Sheet1!$AF$1)+1))))
 
Upvote 0
Confirm with ctrl+shift+enter:
=SUM(IF(Sheet1!F$2:F$500=A2,IF(Sheet1!G$2:G$500=MAX(IF(Sheet1!F$2:F$500=A2,IF(Sheet1!AF$2:AF$500<>"",Sheet1!G$2:G$500))),Sheet1!AF$2:AF$500)))
 
Upvote 0
Hi all, many thanks for the formulas.

They both appear to work well except for one strange quirk....

Sheet 1<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
F-----G-----AF<o:p></o:p>
127--1-----15.6<o:p></o:p>
127--2------3.1<o:p></o:p>
128--1------2.0 <o:p></o:p>
128--2------5.5<o:p></o:p>
129--1------2.5<o:p></o:p>
129--2------1.6<o:p></o:p>
129--3------2.7<o:p></o:p>
130--1------3.3<o:p></o:p>
130--2------3.1<o:p></o:p>
130--3------1.6<o:p></o:p>
130--4------5.4<o:p></o:p>
130--5------<o:p></o:p>
130--6------

If i were to enter a new value under Column AF (see highlighted example), i would still get the old value 2.0 and not the new value 5.5. Is this something i am doing wrong? My calculation settings are set to automotic and i have tried re-running the formula.

Cheers again
 
Upvote 0
Both formulae return 5.5 for me. Are you sure your value in AF doesn't contain any leading/trailing spaces?

EDIT: Check that all 3 cells in that row don't contain leading/trailing spaces.
 
Upvote 0
Hi all, many thanks for the formulas.

They both appear to work well except for one strange quirk....

Sheet 1<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
F-----G-----AF<o:p></o:p>
127--1-----15.6<o:p></o:p>
127--2------3.1<o:p></o:p>
128--1------2.0 <o:p></o:p>
128--2------5.5<o:p></o:p>
129--1------2.5<o:p></o:p>
129--2------1.6<o:p></o:p>
129--3------2.7<o:p></o:p>
130--1------3.3<o:p></o:p>
130--2------3.1<o:p></o:p>
130--3------1.6<o:p></o:p>
130--4------5.4<o:p></o:p>
130--5------<o:p></o:p>
130--6------

If i were to enter a new value under Column AF (see highlighted example), i would still get the old value 2.0 and not the new value 5.5. Is this something i am doing wrong? My calculation settings are set to automotic and i have tried re-running the formula.

Cheers again

I'm still assuming that you don't want to sum multiple records associated with a max value...

Control+sshift+enter, not just enter:
Rich (BB code):
=INDEX(Sheet1!$AF$1:$AF$500,MIN(IF(Sheet1!$F$1:$F$500=A1,
  IF(ISNUMBER(Sheet1!$AF$1:$AF$500),
  IF(Sheet1!$G$1:$G$500=MAX(IF(Sheet1!$F$1:$F$500=A1,
  IF(ISNUMBER(Sheet1!$AF$1:$AF$500),Sheet1!$G$1:$G$500))),
   ROW(Sheet1!$AF$1:$AF$500)-ROW(Sheet1!$AF$1)+1)))))
 
Upvote 0
Both formulae return 5.5 for me. Are you sure your value in AF doesn't contain any leading/trailing spaces?

EDIT: Check that all 3 cells in that row don't contain leading/trailing spaces.

Hi again all,

Just to let you know, both formulas work like an absolute dream. I think the above issue i encountered was the time it was taking to re-calculate the formulas (because in my original sheet the range goes into the 1000's).

I cant thank you both enough for this,

Many many thanks,

C
 
Upvote 0
Hi again all,

Just to let you know, both formulas work like an absolute dream. I think the above issue i encountered was the time it was taking to re-calculate the formulas (because in my original sheet the range goes into the 1000's).

I cant thank you both enough for this,

Many many thanks,

C

Add the following record to the sample you posted: You should get different results...

<TABLE style="WIDTH: 192pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=256><COLGROUP><COL style="WIDTH: 48pt" span=4 width=64><TBODY><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 48pt; HEIGHT: 14.4pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=19 width=64 align=right>128</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 width=64 align=right>2</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 width=64 align=right>7.5</TD></TR></TBODY></TABLE>
 
Upvote 0
Add the following record to the sample you posted: You should get different results...

<TABLE style="WIDTH: 192pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=256 border=0><COLGROUP><COL style="WIDTH: 48pt" span=4 width=64><TBODY><TR style="HEIGHT: 14.4pt" height=19><TD class=xl65 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 48pt; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 14.4pt; BACKGROUND-COLOR: transparent" align=right width=64 height=19>128</TD><TD class=xl66 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 48pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" align=right width=64>2</TD><TD class=xl66 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 48pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width=64></TD><TD class=xl66 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 48pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" align=right width=64>7.5</TD></TR></TBODY></TABLE>

But in the sample the OP posted, each combination of columns F and G appear only once.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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