简体   繁体   English

有没有办法根据 Google 表格中的数组中的数据返回列值?

[英]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 列中有学生姓名,在表的 rest 中有他们注册的组:

下面是我的源数据的图像。它在 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.我已经使用 FILTER function 只用一列做类似的事情,但很难将相同的逻辑应用于数组。

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):在解决方案选项卡上,您可以将以下公式粘贴到单元格 A1 中以动态获取所有组(作为标题):

=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 )).它假定数据选项卡上的数据位于 B 到 F 列 ( data:B:F ))。 You can extend F to whatever it needs to be.您可以将F扩展到所需的任何内容。

Then we have the query on the solution tab, in cell A2:然后我们在单元格 A2 中的解决方案选项卡上进行query

=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 {} . query范围在{}中。 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.范围是B列,A列在右边,然后是返回和列C,A列在右边,然后是返回和D列,A列在右边,等等。如果需要扩展列范围,请添加;data:$N,$N:data!$A:$A右侧}其中“N”是下一列字母。

There is a query on this dataset that selects Col2 from the dataset (Names), where Col1 matches the value in cell A1 (Group 1).对此数据集有一个query ,它从数据集(名称)中选择Col2 ,其中Col1与单元格 A1(组 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.您可以将此公式向右拖动,从单元格 A2 到 B2,到 C2,到 D2 等。拖动时唯一发生变化的是where Col1 matches '"&A$1&"' where Col1 matches '"&B$1&"'where Col1 matches '"&C$1&"'等的地方。

在此处输入图像描述

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

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