Index Match

BWMagee

Board Regular
Joined
Feb 18, 2014
Messages
112
Hi, I am using the INDEX, MATCH combination with a number of criteria, but am receiving an incorrect result.

In plain english, here is what I am trying to do.

The formula is entered into "Sheet2" column D.
The value I wish to return is an average of "Sheet1" column Q.
Based on the following criteria:
a) The value in "Sheet2" column A, is found in "Sheet1" column L
b) The value in "Sheet2" column B, is found in "Sheet1" column M
c) The value in "Sheet1" column H, is one of the 5 highest values in that column

I've tried a number of variations without success, but here is the latest formula used:

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Lucida Grande'; color: #000000}span.s1 {color: #006107}span.s2 {color: #ab30d6}span.s3 {color: #a54a29}span.s4 {color: #0057d6}span.s5 {color: #33af4a}span.s6 {color: #ff9c1b}</style>{=AVERAGE(INDEX('Sheet1'!Q:Q,MATCH(1,('Sheet1'!L:L='Sheet2'!A:A)*('Sheet1'!M:M1='Sheet2'!B:B)*(('Sheet1'!H:H>=MAX('Sheet1'!H:H)-5)),0)))}

This returns an answer of '48'.
'48' is the first value in "Sheet1" column Q that meets the three criteria (a, b, c). However, it is not the average. The average should be 40.2 =(48+49+35+45+24)/5.
There are many more values than those in column Q. But those are the 5 that meet the three criteria.

Any help is much appreciated!
 
Re: Index Match Help

You're welcome. Thanks for the feedback.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Re: Index Match Help

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 16.0px; font: 13.0px Verdana; color: #222222 ; -webkit-text-stroke: #222222 }p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 16.0px; font: 13.0px Verdana; color: #222222 ; -webkit-text-stroke: #222222 ; min-height: 16.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 16.0px; font: 13.0px Verdana; color: #222222 ; -webkit-text-stroke: #222222 ; background-color: #ffffff }p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 16.0px; font: 13.0px Verdana; color: #222222 ; -webkit-text-stroke: #222222 ; background-color: #ffffff ; min-height: 16.0px}span.s1 {font-kerning: none; background-color: #ffffff }span.s2 {font-kerning: none}</style>
You're welcome. Thanks for the feedback.


Unfortunately I have now discovered an error. From our example, in Column H you will see that the top 5 values all belong to “Centre” in Column L (9,8,7,6,5), and no other row has a value equal to those. However, adding in more data on my spreadsheet, other rows now have values equal to those (ie. 9,8,7,6,5), and when they do, it gets added into the Q average, despite not fitting our criteria.


Eg. we want to average Q from H14, H10, H11, H8, H12, to give an average of 40.2
But if we change the value in H9 from “4” to “5”, it is now inside the largest five values for that column, and it’s value in Q “27” gets added into the formula, for an average of 45.6


This shouldn’t be happening, as we stated in our IF function that L = A6 (“Centre”). So nothing named “Office” should be included, no matter what number exists in H, and yet, if we change H9 from “4” to “5”, “27” in Q becomes included.


Any ideas?
 
Upvote 0
Re: Index Match Help

H
I
J
K
L
M
N
O
P
Q
8
6​
Centre
48​
9
4​
Office
27​
10
8​
Centre
49​
11
7​
Centre
45​
12
5​
Centre
35​
13
3​
Hotel
38​
14
9​
Centre
24​
15
2​
Office
21​
16
1​
Centre
26​
17
18
average
19
40.2​

<tbody>
</tbody>

I19=AVERAGEIFS(Q8:Q16,L8:L16,L8,H8:H16,">="&SMALL(H8:H16,5))
 
Upvote 0
Re: Index Match Help

If your data is going to be increasing in rows then I think you will have a problem using the SMALL function.

In the example below the 5th smallest value is 5, so the formula will average any values over 5 for Centre. So in this example you would get an average of the top 8 values and not the top 5.
Excel Workbook
HLMQ
4Average
5Centre36
6
7
86Centre48
95Office27
108Centre49
117Centre45
125Centre35
133Hotel38
149Centre24
152Office21
163Centre26
1710Centre30
181Centre21
1912Centre``
2013Centre21
Sheet
 
Upvote 0
Re: Index Match Help

Here is something else to try:

Excel Workbook
AHI
6Centre29
Sheet2
Excel Workbook
HLMQ
86Centre48
928Office27
108Centre49
117Centre45
125Centre35
135Hotel38
149Centre24
152Office21
163Centre26
173Centre30
181Centre21
1912Centre6
2013Centre21
Sheet1
 
Upvote 0
Re: Index Match Help

If your data is going to be increasing in rows then I think you will have a problem using the SMALL function.

In the example below the 5th smallest value is 5, so the formula will average any values over 5 for Centre. So in this example you would get an average of the top 8 values and not the top 5.

Here is something else to try:



Spreadsheet Formulas
CellFormula
I6{=SUMPRODUCT(--(Sheet1!L8:L20=$A$6)*(--(LARGE(IF(Sheet1!$L$8:$L$20=A6,Sheet1!H8:H20),{1,2,3,4,5})=Sheet1!H8:H20))*Sheet1!Q8:Q20)/5}

<tbody>
</tbody>
Formula Array:
Produce enclosing
{ } by entering
formula with CTRL+SHIFT+ENTER!

<tbody>
</tbody>

Thanks for the detailed responses, much appreciated. Yes, in the end I wasn't sure about SMALL, but found a way to adapt AVERAGE(IF nests to use LARGE {1,2,3,4,5} in a way that worked. It combined advice from both yourself and Marzio in the end. Now I have it working I don't want to break it, so will stick with whats there, but if it comes up with any errors, its good to have this new SUMPRODUCT as backup. Thanks!
 
Upvote 0
Re: Index Match Help

Glad you got it worked out. I agree if you have something working best not to change it. What was the formula you came up with in the end?
 
Upvote 0
Re: Index Match Help

Glad you got it worked out. I agree if you have something working best not to change it. What was the formula you came up with in the end?

Well, it was this:
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Verdana; color: #424242}span.s1 {color: #006107}span.s2 {color: #0057d6}span.s3 {color: #ab30d6}span.s4 {color: #a54a29}span.s5 {color: #33af4a}span.s6 {color: #ff9c1b}</style>=AVERAGE(IF('2018F'!$L$2:$L$6755=PvO!$C149,IF('2018F'!$M$2:$M$6755=PvO!$D149,IF('2018F'!$R$2:$R$6755>=55,IF(LARGE('2018F'!$H$2:$H$6755,{1,2,3,4,5}),'2018F'!$S$2:$S$6755-'2018F'!$Z$2:$Z$6755)))))*$F149

But it appears now not to be working - returning only the average according to the other criteria, but not the largest five values from column H. I attempted your new formula, but received #NUM !

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Lucida Grande'; color: #000000}span.s1 {color: #006107}span.s2 {color: #0057d6}span.s3 {color: #ab30d6}span.s4 {color: #a54a29}span.s5 {color: #33af4a}</style>
{=SUMPRODUCT(--('2018F'!$L$2:$L$6755=$B6)*(--(LARGE(IF('2018F'!$L$2:$L$6755=$B6,'2018F'!$H$2:$H$6755),{1,2,3,4,5})='2018F'!$H$2:$H$6755))*'2018F'!$Q$2:$Q$6755)/5}
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,937
Members
449,480
Latest member
yesitisasport

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