查询/枢轴函数:标题标题降序&一个月格式mmmm yyyy

发布于 2025-02-10 04:41:33 字数 1351 浏览 4 评论 0 原文

[目标] 我想创建一个具有查询函数的表,其中它以动态方式计算每个月的“驱动程序”数量。这意味着当数据(示例表被称为“数据”)更新时,它也将自动更新。

[到目前为止我能做的] 我能够创建一个具有查询功能的表,但是,当我想出现长达4个月时,它仅显示1列的数月。而且我还想显示近几个月来左边的几个月和右边的年龄较大的几个月。

[我到目前为止的公式]

=QUERY(Data!$A:$B,"
SELECT B,
Count(B) 
Where B != '' AND MONTH(A)=MONTH(DATE'"&TEXT(A2,"YYYY-MM-DD")&"')
Group By B 
Pivot A
Order By B asc
Label B 'Drivers', Count(B) '"&TEXT(A2,"MMMM YYYY")&"'",1)

[我面临的问题] 我已经尝试指定下面的日期范围,但是有2个问题。

  1. 日期格式不是mmmm yyyy(示例:2022年5月),它显示为:2022-2-1,2022年5月
  2. 以上订购的月份(示例:20222-2-1,2022-3-1, 2022-4-1)代替下降(示例:2022-4-1,2022-3-1,2022-2-1),

所以我不确定要解决这个问题。希望我能得到支持。

Where B != '' AND MONTH(A)<=MONTH(DATE'"&TEXT(A2,"YYYY-MM-DD")&"')
AND MONTH(A)>=MONTH(DATE'"&TEXT(EDATE(A2,-3),"YYYY-MM-DD")&"')

[示例表]

[Goal]
I want to create a table with the Query Function where it counts the number of 'Drivers' for each month in a dynamic manner. Meaning that when the data (example sheet is called 'Data') is updated, it'll be updated automatically as well.

[What I was able to do so far]
I was able to create a table with the Query Function, however, it only displays 1 column worth of Months when I want to show up to 4 months. And I also want to show the recent months from the left and the older months on the right.

[Formula that I have so far]

=QUERY(Data!$A:$B,"
SELECT B,
Count(B) 
Where B != '' AND MONTH(A)=MONTH(DATE'"&TEXT(A2,"YYYY-MM-DD")&"')
Group By B 
Pivot A
Order By B asc
Label B 'Drivers', Count(B) '"&TEXT(A2,"MMMM YYYY")&"'",1)

[Issue that I'm facing]
I've tried specifying the date range like the below, however there are 2 problems.

  1. The date format is not mmmm yyyy (Example: May 2022) and it'd show as: 2022-2-1 May 2022
  2. The months are ordered in an ascending manner (Example: 2022-2-1, 2022-3-1, 2022-4-1) instead of descending (Example: 2022-4-1, 2022-3-1, 2022-2-1)

So I'm not sure what I need to do to fix this. Hopefully I can have support.

Where B != '' AND MONTH(A)<=MONTH(DATE'"&TEXT(A2,"YYYY-MM-DD")&"')
AND MONTH(A)>=MONTH(DATE'"&TEXT(EDATE(A2,-3),"YYYY-MM-DD")&"')

enter image description here

[Sample Sheet]
https://docs.google.com/spreadsheets/d/1AJYTRga9-dXbj64nl4RfpDKs5JYSFwP2SiR7v7gAhMI/edit#gid=1297239620

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事和酒 2025-02-17 04:41:33
=ARRAYFORMULA(REGEXREPLACE(""&TRANSPOSE(QUERY(TRANSPOSE(
QUERY({Data!A:B, TEXT(Data!A:A, "yyyymmdd×MMMM yyyy")}, 
 "select Col2,count(Col2) 
  where Col2 != ''
    AND MONTH(Col1)<=MONTH(DATE'"&TEXT(A2,"YYYY-MM-DD")&"')
    AND MONTH(Col1)>=MONTH(DATE'"&TEXT(EDATE(A2,-3),"YYYY-MM-DD")&"')
  group by Col2 
  pivot Col3", 1)),"order by Col1 desc")),"^(.*×)", ))

参考:

我如何更改Google表格中的日期格式查询日期枢轴表格使用日期过滤器?

排序查询枢轴表 - Google表格

=ARRAYFORMULA(REGEXREPLACE(""&TRANSPOSE(QUERY(TRANSPOSE(
QUERY({Data!A:B, TEXT(Data!A:A, "yyyymmdd×MMMM yyyy")}, 
 "select Col2,count(Col2) 
  where Col2 != ''
    AND MONTH(Col1)<=MONTH(DATE'"&TEXT(A2,"YYYY-MM-DD")&"')
    AND MONTH(Col1)>=MONTH(DATE'"&TEXT(EDATE(A2,-3),"YYYY-MM-DD")&"')
  group by Col2 
  pivot Col3", 1)),"order by Col1 desc")),"^(.*×)", ))

Reference:

How do I change the date format in a Google Sheets query pivot table with date filters?

Sort Query Pivot Table - Google Sheets

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文