简体   繁体   English

多个条件和多个列的Excel查找值

[英]Excel lookup value for multiple criteria and multiple columns

I am helping a friend with some data analysis in Excel. 我正在帮助一个朋友在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). 现在,对于每个分类和每个生产商,我们生成了一个列表,该列表显示了9个供应商中哪个提供了最低的价格(按数量计算,例如,C类中有2辆来自AUDI的汽车,因此供应商A会同时提供最低的价格)。

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. 因此,如果我们看到卖主A在C类中的AUDI汽车的价格最低,那么我们想知道卖主A在这些汽车中的平均价格。

I'm quite stumped since I can't use the "standard" index-match-small approach since the prices are stored in 9 different columns. 我很沮丧,因为我无法使用“标准”的“小索引匹配”方法,因为价格存储在9个不同的列中。

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.). 我建议使用一个长的if链,例如:= if(vendor = A,averageif(输入条件并选择供应商A的列作为平均值),if(vendor = B,average(输入条件并输入选择供应商B的列作为平均值),等等。

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. 这可以通过使用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: 例如,如果您的第二张表在单元格M2:M [end]中有一列用于分类的列,则计算供应商1提供的Audi C类的平均价格可能是:

=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: 例如,在我的示例图像中,audi C类的最便宜供应商将是:

=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). 如果这是一次性的事情,那么我会走那条路线,如果需要将其自动化,然后尝试使用多条件VLOOKUP(需要以矩阵公式形式输入: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/ chandoos网站上提供了更好的解释: http ://chandoo.org/wp/2014/10/28/multi-condition-vlookup/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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