Google 表格 - 查询按下拉列表过滤并按相关下拉列表排序

问题描述 投票:0回答:1

我想让学生列表更加灵活和用户友好,而不仅仅是一大堆数据。

我希望通过过滤和排序来组合几个不同的功能,同时使用复选框来选择或删除列。第一种是使用依赖下拉列表来过滤数据使用此公式

=QUERY(O14:V34,"SELECT "&TEXTJOIN(", ",TRUE,ArrayFormula(IF(O13:V13,"Col"&(COLUMN(O14:V14)-COLUMN(O14)+1) ,"")))
& " WHERE Col1 is not null "
&IF(D3="All Teachers",""," AND LOWER(Col1) = LOWER('" &D3&"') ")
&IF(E3="All Schools",    ""," AND LOWER(Col4) = LOWER('" &E3&"') ")
&IF(G3="All",    ""," AND LOWER(Col5) = LOWER('" &G3&"') ") 
 ,1)

第二个是提供使用依赖下拉列表对列表进行排序/排序的选项。

=QUERY(O14:V34,"SELECT "&TEXTJOIN(", ",TRUE,ArrayFormula(IF(O13:V13,"Col"&(COLUMN(O14:V14)-COLUMN(O14)+1) ,"")))
& " WHERE Col1 is not null order by Col"&MATCH(D34, O14:V14, 0)
,1)

组合时(无论如何可能是错误的),排序选项将起作用,但仅当“所有教师”、“所有学校”或“全部”时,但当仅选择一个值(例如“John”)时,它将中断,如错误中所示以下。否则,我可以对各个列进行排序。

=QUERY(O14:V34, "Select "&TEXTJOIN(", ",TRUE,ArrayFormula(If(O13:V13,"Col"&(COLUMN(O14:V14)-COLUMN(O14)+1),""))) 
& " WHERE Col1 is not null ORDER By Col"&MATCH(D34, O14:V14, 0)&" "&G1
 &IF(D3="All Teachers",""," AND LOWER(Col1) = LOWER('" &D3&"') ") 
&IF(E3="All Schools", ""," AND LOWER(Col2) = LOWER('" &E3&"') ")
&IF(G3="All", ""," AND LOWER(Col2) = LOWER('" &G3&"') ") 
,1)

错误
无法解析函数 QUERY 参数 2 的查询字符串:PARSE_ERROR:在第 1 行第 93 列遇到“”和““AND””。预期为以下之一:“跳过”...“限制”...“偏移” ...“标签”...“格式”...“选项”...“asc”...“desc”...“,”...“*”...“+”.. “-”...“/”...“%”...“*”...“/”...“%”...“+”...“-”...

用于测试的 Google 表格

这是我尝试完成的另一个解决方案,位于示例表的右下角。这取得了一些成功,但我不清楚如何引入更多 IF 语句,因为我需要 4-5 个排序选项,而不仅仅是 2 个。

=IF( D34="", ,SORT(QUERY(O13:V32,"SELECT "&TEXTJOIN(", ",TRUE,ArrayFormula(IF(O11:V11,"Col"&(COLUMN(O12:V12)-COLUMN(O12)+1) ,"")))
& " WHERE Col1 is not null "
&IF(D3="All Teachers",""," AND LOWER(Col1) = LOWER('" &D3&"') ")
&IF(E3="All Schools",    ""," AND LOWER(Col4) = LOWER('" &E3&"') ")
&IF(G3="All",    ""," AND LOWER(Col5) = LOWER('" &G3&"') ") 
 ,1), IF( D34="Teacher", 1, IF( D34="Home School", 4, 1)), IF( D34="Teacher", True, 1)))

有关查询“ORDER BY”或“Sort()”解决方案的任何帮助都将是令人惊奇的。谢谢!

我对 Google Sheets 还很陌生,尤其是在使用查询功能时,但我很想学习。

谢谢!

google-sheets drop-down-menu google-sheets-formula
1个回答
0
投票

您可以尝试将

ORDER
语句移到条件参数之后:

=QUERY(O12:V32, "Select "&TEXTJOIN(", ",TRUE,ArrayFormula(If(O11:V11,"Col"&(COLUMN(O12:V12)-COLUMN(O12)+1),""))) & " WHERE Col1 is not null"
 &IF(D3="All Teachers",""," AND LOWER(Col1) = LOWER('" &D3&"') ") 
&IF(E3="All Schools", ""," AND LOWER(Col4) = LOWER('" &E3&"') ")
&IF(G3="All", ""," AND LOWER(Col5) = LOWER('" &G3&"') ")&"

ORDER By Col"&MATCH(D34, O12:V12, 0)
,1)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.