如何解决在Google表格查询中的日期筛选问题?

huangapple go评论65阅读模式
英文:

How do i resolve this date filter issue in a google sheets query?

问题

第B列显示的是标准日期格式。这个查询用于生成我的多个医疗类别支出的表格。

B314单元格中的日期是1/1/2021,C314单元格中输入的是12/31/2021。我只想显示2021年的交易。这个日期筛选器不起作用,因为它继续显示来自2022年和2023年的交易。

=QUERY(Transactions!B1:Transactions!F8094, "选择 B,C,D,E 其中 B >= 日期 '"&TEXT(B314,"yyyy-mm-dd")&"' 并且 B <= 日期 '"&TEXT(C314,"yyyy-mm-dd")&"' 并且 D= '个人 - 医疗费用' 或 D='个人 - 旅行' 或 D='个人 - 医疗保险' 按 B 排序",1)

当我删除日期单元格引用并输入完整表达式时,同样的情况发生:

=QUERY(Transactions!B1:Transactions!F8094, "选择 B,C,D,E 其中 B >= 日期 '"&TEXT(DATEVALUE("1/1/2021"),"yyyy-mm-dd")&"' 并且 B <= 日期 '"&TEXT(DATEVALUE("12/31/2021"),"yyyy-mm-dd")&"' 并且 D= '个人 - 医疗费用' 或 D='个人 - 旅行' 或 D='个人 - 医疗保险' 按 B 排序",1)

我尝试了许多小的更改,但无法使其工作。我是一个新手,对查询不太熟悉。

英文:

Column B on my Transactions Tab shows Dates in standard date format.

This query works to produce a table of my expenses for several medical categories.

Cell B314 has the date 1/1/2021, Cell C314 has 12/31/2021 entered. I just want to show transactions for 2021. This date filter dies not work as it continues to show transactions from 2022 and 2023

=QUERY(Transactions!B1:Transactions!F8094,"Select B,C,D,E Where B >= date '"&TEXT(B314,"yyyy-mm-dd")&"' AND B <= date '"&TEXT(C314,"yyyy-mm-dd")&"' AND D= 'Personal - Medical Expense' or D='Personal - Travel' or D='Personal - Medical Insurance' ORDER BY B",1)

The same things happens when I remove the date cell references and enter the full expression:

=QUERY(Transactions!B1:Transactions!F8094,"Select B,C,D,E where B >= date '"&TEXT(DATEVALUE("1/1/2021"),"yyyy-mm-dd")&"' AND B <= date '"&TEXT(DATEVALUE("12/31/2021"),"yyyy-mm-dd")&"' AND D= 'Personal - Medical Expense' or D='Personal - Travel' or D='Personal - Medical Insurance' ORDER BY B",1)

I tried many small changes but cannot get it to work. Im a rookie with queries.

答案1

得分: 0

我认为您的问题出现在OR语句中。尝试使用以下查询:

=QUERY(Transactions!B1:F8094,"Select B,C,D,E Where B >= date '"&TEXT(B314,"yyyy-mm-dd") & 
"' AND B <= date '"&TEXT(C314,"yyyy-mm-dd")&
"' AND (D= 'Personal - Medical Expense' or D='Personal - Travel' or D='Personal - Medical Insurance') ORDER BY B",1)
英文:

I assume your problem in OR statement. Give a try on below query.

=QUERY(Transactions!B1:F8094,&quot;Select B,C,D,E Where B &gt;= date &#39;&quot;&amp;TEXT(B314,&quot;yyyy-mm-dd&quot;) &amp; 
&quot;&#39; AND B &lt;= date &#39;&quot;&amp;TEXT(C314,&quot;yyyy-mm-dd&quot;)&amp;
&quot;&#39; AND (D= &#39;Personal - Medical Expense&#39; or D=&#39;Personal - Travel&#39; or D=&#39;Personal - Medical Insurance&#39;) ORDER BY B&quot;,1)

huangapple
  • 本文由 发表于 2023年2月10日 09:55:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定