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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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

[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
H
[/TD]
[TD]
I
[/TD]
[TD]
J
[/TD]
[TD]
K
[/TD]
[TD]
L
[/TD]
[TD]
M
[/TD]
[TD]
N
[/TD]
[TD]
O
[/TD]
[TD]
P
[/TD]
[TD]
Q
[/TD]
[/TR]
[TR]
[TD]
8
[/TD]
[TD]
6​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Centre[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
48​
[/TD]
[/TR]
[TR]
[TD]
9
[/TD]
[TD]
4​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Office[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
27​
[/TD]
[/TR]
[TR]
[TD]
10
[/TD]
[TD]
8​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Centre[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
49​
[/TD]
[/TR]
[TR]
[TD]
11
[/TD]
[TD]
7​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Centre[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
45​
[/TD]
[/TR]
[TR]
[TD]
12
[/TD]
[TD]
5​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Centre[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
35​
[/TD]
[/TR]
[TR]
[TD]
13
[/TD]
[TD]
3​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Hotel[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
38​
[/TD]
[/TR]
[TR]
[TD]
14
[/TD]
[TD]
9​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Centre[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
24​
[/TD]
[/TR]
[TR]
[TD]
15
[/TD]
[TD]
2​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Office[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
21​
[/TD]
[/TR]
[TR]
[TD]
16
[/TD]
[TD]
1​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Centre[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
26​
[/TD]
[/TR]
[TR]
[TD]
17
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
18
[/TD]
[TD][/TD]
[TD]average[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
19
[/TD]
[TD][/TD]
[TD]
40.2​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

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,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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