简体   繁体   中英

Is there a way of returning a column value based on data in an array in Google sheets?

Below is an image of my source data. I am using Google Sheets. It has student names in Column A, and the groups that they have signed up for in the rest of the table:

下面是我的源数据的图像。它在 A 列中有学生姓名,在表格的其余部分有他们注册的组

I am trying to look for all instances of each group in the array, and then return all of the names linked to that group. Please refer to the image below for what I'm after.

Final table:

决赛桌

I have used the FILTER function to do something similar with just a column, but am stumped to apply the same logic to an array.

Update

Assuming your data is on a tab called 'data', like this:

在此处输入图像描述

I've created another tab for the solution.

On the solution tab, you can paste the following formula into cell A1 to dynamically get all of your Groups (as headings):

=arrayformula(transpose(query(unique(flatten(data:B,F)),"where Col1 is not null",0)))

在此处输入图像描述

It assumes data on the data tab is in columns B to F ( data:B:F )). You can extend F to whatever it needs to be.

Then we have the query on the solution tab, in cell A2:

=query({data:$B,$B:data;$A:$A,data:$C;$C:data,$A:$A;data:$D,$D:data;$A:$A,data:$E,$E,data,$A:$A;data!$F:$F,data!$A:$A},"select Col2 where Col1 matches '"&A$1&"' order by Col1,Col2",0)

The query range is in {} . Note the , and the ; within the range.

, is a new row, ; is a return. The range is column B with column A to the right, then a return and column C with column A to the right, then a return and column D with column A to the right, etc. If you need to extend the column range, add ;data:$N,$N:data!$A:$A within the right } where 'N' is the next column letter.

There is a query on this dataset that selects Col2 from the dataset (Names), where Col1 matches the value in cell A1 (Group 1).

在此处输入图像描述

You can drag this formula to the right, from cell A2 to B2, to C2, to D2 etc. The only thing that changes whilst dragging is where Col1 matches '"&A$1&"' changes to where Col1 matches '"&B$1&"' to where Col1 matches '"&C$1&"' etc.

在此处输入图像描述

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