VLookup all occurrences of value to get average

cgcamal

Active Member
Joined
May 2, 2007
Messages
472
Hi to all,

Hoping somebody could help me.

I have this table:
Excel Workbook
ABCDEF
1234.16666667
2
313122
43531-3
542502
6517-11
7279-23
81411-31
93213-46
105715-53
1111217-64
123419-72
132121-89
148223-91
155925-102
...

And I want to look up, in columns A and B,
the value in A1=2, but I need something like an extension of "VLookup"
to get all values in Column E (values in green) in the same row of each "2" found and obtain the the average of
those values in green that is 4.16666667 as in cell F1.
Cell Formulas
RangeFormula
B1=VLOOKUP(A1,A3:E15,5,FALSE)
F1=AVERAGE(E5,E7,E9,E11,E13,E14)

The issue with VLOOKUP is that returns only the first match for first value in column A. I think an array formula will do
the trick, because it could be many matches, not only 6 as in the sample.

Thanks in advance for any help.

Regards,
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Using your posted example,
this regular formula returns the average of Col_E cells
where the corresponding Col_A OR Col_B cell equals 2.

F1: =SUMPRODUCT((A3:B15=2)*E3:E15)/COUNTIF(A3:B15,2)

Note: that formula assumes that the number 2 will NOT occur twice in the same row.

Is that something you can work with?
 
Upvote 0
Hey Ron,

Thanks for your help. Much more simpler than I was thinking and trying to do without success.

That works perfect, because the value "2" only occurs once in the same row.

Many thanks again.

Best regards
 
Upvote 0
Hi to all,

Hoping somebody could help me.

I have this table:
#VALUE!
#VALUE!

And I want to look up, in columns A and B, the value in A1=2, but I need something like an extension of "VLookup"
to get all values in Column E (values in green) in the same row of each "2" found and obtain the the average of
those values in green that is 4.16666667 as in cell F1.
Cell Formulas
RangeFormula
B1=VLOOKUP(A1,A3:E15,5,FALSE)
F1=AVERAGE(E5,E7,E9,E11,E13,E14)

The issue with VLOOKUP is that returns only the first match for first value in column A. I think an array formula will do
the trick, because it could be many matches, not only 6 as in the sample.

Thanks in advance for any help.

Regards,
Here's another one...

Array entered**:

=AVERAGE(IF((A3:A15=A1)+(B3:B15=A1),E3:E15))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
 
Upvote 0
Hi T. Valko,

I've tested it and works correctly too.

Many thanks for your help.

Best regards.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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