[目标]
我想创建一个具有查询函数的表,其中它以动态方式计算每个月的“驱动程序”数量。这意味着当数据(示例表被称为“数据”)更新时,它也将自动更新。
[到目前为止我能做的]
我能够创建一个具有查询功能的表,但是,当我想出现长达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个问题。
- 日期格式不是mmmm yyyy(示例:2022年5月),它显示为:2022-2-1,2022年5月
- 以上订购的月份(示例: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.
- The date format is not mmmm yyyy (Example: May 2022) and it'd show as: 2022-2-1 May 2022
- 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")&"')

[Sample Sheet]
https://docs.google.com/spreadsheets/d/1AJYTRga9-dXbj64nl4RfpDKs5JYSFwP2SiR7v7gAhMI/edit#gid=1297239620
发布评论
评论(1)
参考:
我如何更改Google表格中的日期格式查询日期枢轴表格使用日期过滤器?
排序查询枢轴表 - Google表格
Reference:
How do I change the date format in a Google Sheets query pivot table with date filters?
Sort Query Pivot Table - Google Sheets