INDEX合并两列,其中一列跨越多行

时间:2018-11-04 15:02:09

标签: excel google-sheets

我的基于this answer to VLOOKUP by Combining 2 Columns to Form a Unique Key questionINDEX公式在MATCH的{​​{1}}参数之一跨越多行的情况下不起作用:

lookup_range

用法:

=INDEX($C$3:$C$5, MATCH($A$3 & $B$3, $A$3:$A$5 & $B$3:$B$5, 0))
                                     ^       ^
                                     |       |
                                     +---+---+
                                         |
                      lookup_range column spans multiple rows

此表有效

+---+------+-------+---------------+-----------------+----------------+
| \ |   A  |   B   |       C       |        D        |        E       |
+---+------+-------+---------------+-----------------+----------------+
| 1 |                               CARS                              |
+---+-----------------------------------------------------------------+
| 2 | Make | Model | Current price | Production Year | Original price |
+---+------+-------+---------------+-----------------+----------------+
| 3 | Audi | A1    | 40000         | 2013            | =MY_FORMULA    |
+---+------+-------+---------------+-----------------+----------------+
| 4 | Audi | A2    | 50000         | 2010            | =MY_FORMULA    |
+---+------+-------+---------------+-----------------+----------------+
| 5 | Audi | A3    | 60000         | 2014            | =MY_FORMULA    |
+---+------+-------+---------------+-----------------+----------------+

此表不起作用(我希望它):

+---+------+-------+-------+
| \ |   A  |   B   |   C   |
+---+------+-------+-------+
| 1 |        Prices        |
+---+----------------------+
| 2 | Make | Model | Price |
+---+------+-------+-------+
| 3 | Audi | A1    | 50000 |
+---+------+-------+-------+
| 4 | Audi | A2    | 60000 |
+---+------+-------+-------+
| 5 | Audi | A3    | 70000 |
+---+------+-------+-------+

很明显,将 AUDI 值跨多行可以避免冗余和错别字。我该如何实现?

1 个答案:

答案 0 :(得分:2)

您应该能够通过如下所示的vlookup在Google表格中执行此操作:-

=ArrayFormula(vlookup(E3&F3,{vlookup(row(A$3:A$10),{if(A$3:A$10<>"",row(A$3:A$10)),A$3:B$10},2)&B$3:B$10,C$3:C$10},2,false))

内部vlookup查找包含行号小于或等于当前行的汽车品牌的最后一行。如果愿意,外部vlookup可以是索引匹配,并且可以通过放置A $ 3:A等将范围扩展到最后一行。

enter image description here


为完整起见,在Excel中,您必须哄骗Index函数为您提供一个可以在see this上使用的数组

=INDEX(C$3:C$10,MATCH(E3&F3,INDEX(A$3:A$10,N(IF({1},MATCH(ROW(A$3:A$10),IF(A$3:A$10<>"",ROW(A$3:A$10))))))&B$3:B$10,0))

输入为数组公式。