如何让我的 Google 表格查询自动从年份下拉选项卡中提取?

时间:2021-06-12 17:11:53

标签: google-sheets google-sheets-formula

https://docs.google.com/spreadsheets/d/1kXFh-OWeFxFKuqnX9WAP3JDwo9cz5cR73Z4bp0IUVTo/edit?usp=sharing

我试图让我的查询函数根据下拉选项卡中选择的年份自动更新。

我有这个用于前景表:

=Query('BNTouch Raw Data'!$A$1:CL,"
SELECT AF, sum(L), avg(L), count(L)
WHERE BO contains 'Prospect' and BD >= Date '2021-01-01' and BD <= Date '2021-12-31'
GROUP by AF
ORDER BY sum(L) desc
LIMIT 7
LABEL sum(L) 'Total Loan Amount', count(L) 'Loan Quantity', avg(L) 'Average Loan Amount' ")

并考虑将我在工作表输入 - ColumnCL2 和 ColumnCL3 中计算的范围放入“行项目所在位置”。

比如:

WHERE BO contains 'Prospect' and BD >= Date 'CL2' and BD <= Date 'CL3'

但显然这行不通。关于如何在选择下拉年份时自动更新查询的任何想法?

2 个答案:

答案 0 :(得分:0)

使用:

=Query('BNTouch Raw Data'!$A$1:CL,"
 SELECT AF, sum(L), avg(L), count(L)
 WHERE BO contains 'Prospect' 
   and BD >= Date '"&TEXT(CL2, "yyyy-mm-dd")&"' 
   and BD <= Date '"&TEXT(CL3, "yyyy-mm-dd")&"'
 GROUP by AF
 ORDER BY sum(L) desc
 LIMIT 7
 LABEL sum(L) 'Total Loan Amount', count(L) 'Loan Quantity', avg(L) 'Average Loan Amount' ")

答案 1 :(得分:0)

@player0

我能够使用你的建议来解决这个问题:

=Query('BNTouch Raw Data'!$A$1:CN,
if($I$9<>"","
SELECT AF, sum(L), avg(L), count(L)
WHERE BO contains 'Prospect' 
 and BD >= date """&TEXT($F$9,"yyyy-MM-dd")&""" 
 and BD <= date """&TEXT($F$11,"yyyy-MM-dd")&"""
 and AF = '"&$I$9&"'
GROUP by AF
ORDER BY sum(L) desc
LIMIT 16
LABEL sum(L) 'Total Loan Amount', count(L) 'Loan Quantity', avg(L) 'Average Loan Amount' ","
SELECT AF, sum(L), avg(L), count(L)
WHERE BO contains 'Prospect' 
 and BD >= date """&TEXT($F$9,"yyyy-MM-dd")&""" 
 and BD <= date """&TEXT($F$11,"yyyy-MM-dd")&"""
GROUP by AF
ORDER BY sum(L) desc
LIMIT 16
LABEL sum(L) 'Total Loan Amount', count(L) 'Loan Quantity', avg(L) 'Average Loan Amount' "))