tableau-api - 按工作日划分的月平均新用户数
问题描述
我的数据由fully_enrolled_at
维度和new_users
度量组成。因此,这不需要数据集,因为您可以sum()
进行任何日期和测量。
我创建了以下 2 个计算:
这是该月的日历天数
days_in_month = DATEDIFF('day',MIN(DATETRUNC('month',[fully_enrolled_at])),MAX(DATETRUNC('month',DATEADD('month',1,[fully_enrolled_at]))))
这会将当前月份的日历天数更改为经过的天数:
days_in_all_months = IF MIN(DATETRUNC('month',today()))=MAX(DATETRUNC('month',[fully_enrolled_at])) THEN 1+DATEDIFF('day',DATETRUNC('month',today()),today()) ELSE [days_in_month] END
然后我绘制:discrete month(fully_enrolled_at) as dimension, and sum([new_users])/[days_in_all_months]
作为度量。
这给了我想要的东西,但是我想计算每个月的工作日,而不是日历月。
如何删除周末和国定假日days_in_all_months
(而本月应该有 # 个工作日)?假期名单:https ://gist.github.com/jameslin101/cf2860eba52a56281427#file-csv-of-us-stock-market-holidays-through-2020
你能帮忙调整一下吗?谢谢!
解决方案
您可以设置当前Day和 WorkingDaysTotal。然后包括一个IF语句。
如果 Day = 周六或周日什么都不做 WorkingDaysTotal = WorkingDaysTotal + 1
这在理论上会给你工作日的数量。
您还需要:
如果该月的第一天,则 WorkingDaysTotal = 0
最后,再次检查该月的第一天是周六还是周日。
国定假日会更加棘手,因为不同的国家、宗教等有不同的假期。因此,您必须事先设置这些日期。
编辑
这是您想要的工作示例,不包括假期和周末。
=AVERAGE(IF(WEEKDAY(C7:I7,2)<6,IF(ISERROR(MATCH(C7:I7,Holidays,FALSE)),C8:I8)))
where C7:I7 has the dates, C8:I8 has the data, and Holidays is a named range of holiday dates. If you further want to exclude 0 values, then use this array formula
=AVERAGE(IF(WEEKDAY(C7:I7,2)<6,IF(ISERROR(MATCH(C7:I7,Holidays,FALSE)),IF(C8:I8>0,C8:I8))))
推荐阅读
- php - PHP邮件编码问题
- javascript - 当部分滚动到视图中时启用代码工作
- javascript - 如何使用对象的索引删除数组中的对象
- dataframe - MultiLabelBinarizer() 正在拟合列但不转换它的值
- java - 当我尝试在 java 中获取 implementationversion() 时,为什么会得到 null?
- php - 如何使用 PHP 访问 iCloud 日历?
- java - 所有文件夹名称都没有出现在 Amazon S3 的列表对象调用中
- android-management-api - JSON 解析错误:无法设置 com.google.api.services.androidmanagement.v1.model.KioskCustomization 字段
- sql - 过滤部分时间戳的最佳方法是什么?
- javascript - 如何按id过滤行并重绘数据表