简体   繁体   English

Google表格中数组中的索引匹配

[英]Index Match in Array in Google Sheets

I have a spreadsheet 'Database' where there are two columns, 'Countries' (A) and 'Companies'(B). 我有一个电子表格“数据库”,其中有两列,“国家”(A)和“公司”(B)。 Countries are numbered from 1-10. 国家编号从1到10。 Companies are labelled with letters. 公司标有字母。

The spreadsheet tracks the companies that operate in each country. 电子表格跟踪在每个国家/地区运营的公司。 As such, a row that has Country 1 in column A and Company A in column B means that Company A operates in country 1. This is a screenshot from this spreadsheet: 因此,在A列的国家1和B列的公司A的行表示公司A在国家1中运营。这是此电子表格的屏幕截图:

在此处输入图片说明

I then have a second spreadsheet called 'Countries by Company' where I would like to list the countries in which a company operates. 然后,我还有第二个电子表格,称为“公司国家/地区”,我想在其中列出公司运营所在的国家/地区。 I would like them to be listed in different rows starting form cell B3 of the 'Countries by Company' sheet. 我希望它们在“按国家(地区)”表的单元格B3开头的不同行中列出。 The company name for which the countries should be listed is in cell B1 of the same sheet. 在同一工作表的B1单元格中应列出国家/地区的公司名称。 I gather this has to be done with an ARRAY version of an INDEX MATCH function but I can't seem to get it to work. 我认为必须使用ARRAY版本的INDEX MATCH函数来完成此操作,但是我似乎无法使其正常工作。

I have put the following formula in cell B3 of the 'Countries by Company' sheet: =INDEX(Database!$A$1:$B$76, MATCH($B$1, Database!$B$1:$B$76, 0), COLUMN(Database!A:A)) . 我在“按公司划分的国家”工作表的单元格B3中输入了以下公式: =INDEX(Database!$A$1:$B$76, MATCH($B$1, Database!$B$1:$B$76, 0), COLUMN(Database!A:A)) However, as expected, it will only return the first country in which the company in cell B1 operates and no other country. 但是,正如预期的那样,它将仅返回单元格B1中公司在其中运营的第一个国家,而不会返回其他国家。 Again, I would need all countries in which that company operates listed in different rows from cell B3. 同样,我需要该公司运营所在的所有国家/地区与B3单元格不同。

I have set up a sample sheet in here . 我在这里设置了一个样本表。 I thought it might help in case I wasn't too clear. 我认为这可能会有所帮助,以防我不太清楚。

Thanks for your help! 谢谢你的帮助!

Using FILTER allows restricting the values on the Database sheet to only those that match a given criteria: 使用FILTER可以将“数据库”表上的值限制为仅与给定条件匹配的值:

=FILTER(Database!$A:$A, Database!$B:$B=$B$1)

yields every country index for the given company index on the Database sheet. 产生Database表上给定公司索引的每个国家/地区索引。 If only the country index values (eg 1, 3, 6) are desired, rather than converting those index values to a name or other property that is held in a hypothetical "Country DB" sheet, the above FILTER is sufficient. 如果只需要国家索引值(例如1、3、6),而不是将这些索引值转换为假设的“国家DB”表中保存的名称或其他属性,则上述FILTER足够了。

If additional information is desired, then VLOOKUP can be used to return the corresponding values for multiple inputs (ie an array input): 如果需要其他信息,则可以使用VLOOKUP返回多个输入(即数组输入)的相应值:

B3:  =ARRAYFORMULA(VLOOKUP(
         FILTER('Database'!$A:$A, 'Database'!$B:$B=$B$1),  // Searched values
         'Country DB'!$A:$B,                               // Database sheet having more country information (like name, gdp, ...)
         2,                                                // Column of the desired information
         FALSE))

will yield the 2nd column from each corresponding country index row in the "Country DB" sheet: 将在“国家/地区数据库”表中每个相应的国家/地区索引行中产生第二列:

显示国家名称

尝试使用过滤器

=filter(Database!A2:B,Database!A2:A=B1)

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

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