简体   繁体   中英

Excel lookup value for multiple criteria and multiple columns

I am helping a friend with some data analysis in Excel. Here's how our data looks like:

Car producer | Classification | Prices from 9 different vendors in 9 columns
AUDI | C | 100 200 300 400 500 600 700 800 900
AUDI | C | 100 900 800 200 700 300 600 400 500
AUDI | B | .. ..

Now, for each classification and each producer, we produced a list that shows which of the 9 vendors has offers the most lowest prices (in terms of count, so for example there are 2 cars from AUDI in the C class, so vendor A would offer the lowest price for both).

What we need: A way to calculate the average price for this vendor. So, if we see that the vendor A has the lowest price for AUDI cars in the C class, then we want to know the average price for vendor A for these cars.

I'm quite stumped since I can't use the "standard" index-match-small approach since the prices are stored in 9 different columns.

I've suggested to use a long if-chain like this: =if(vendor=A,averageif(enter the criteria and select the column of vendor A for average values),if(vendor=B,average(enter the criteria and select the column of vendor B for average values),... etc.).

But this method is obviously limited and does not scale well to higher dimensions.

We also would like to avoid using any addons.

You're going to need to create a separate table that has all unique classifications in the rows and all dealers in the columns (same as yours, but with duplicate rows removed). Then, in each cell, take the average price for that classification*vendor combination. This can be done by using a combination of sumif/countif. For example, if your second table had a column for classifications in cells M2:M[end], calculating the average price for the Audi C class offered by vendor 1 could be:

=sumif(C$2:C$[end],"="&$M2,$B$2:$B$[end])/countif($B$2:$B$[end],"="&$M2)

This would look something like this: 使用sumif / countif汇总表数据

Then you could simply find the cheapest vendor by matching the min price. For example, the cheapest vendor for the audi C class in my example image would be:

=index($N$1:$V$1,match(min($N2:$V2),$N2:$V2,0))

A lot this could be done using PivotTables. If it is a one off thing, I would go that route, if it needs to be automated, then try using a multicondtional VLOOKUP (needs to be entered as a Matrix Formula: CTRL+ALT+SHIFT). This is simply an example, not based on your data:

{=VLOOKUP(A11&B11,CHOOSE({1\2},A2:A7&B2:B7,C2:C7),2,0)}

A better explanation is given here at chandoos site: http://chandoo.org/wp/2014/10/28/multi-condition-vlookup/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM