powerbi - DAX 计算所有 7 天的平均值 数量值
问题描述
| DateTime | Quantity |
|:--------------------- |: ---------- |
| 6/8/2021 1:00PM | 89 |
| 6/7/2021 8:00PM | 99 |
| 6/6/2021 11:00PM | 70 |
| 6/5/2021 9:00PM | 60 |
| 6/4/2021 5:00AM | 55.5 |
| 6/3/2021 11:00PM | 53 |
| 6/2/2021 12:00AM | 99 |
| 6/1/2021 6:00PM | 100 |
I tried the following code but not giving me the correct result. There are two varaibles. Not sure if it's correct way.
"Average Last 7 Days=
var All_Hours= CALCULATE(AVERAGE(Table1[Quantity]), ALLSELECTED(Table1))
var lastOneWeek = LastOneHour - TIME(168,0,0) '''168 is for the past '''7 days hour.
return CALCULATE([Quantity] , FILTER(ALL(Table1), SystemMetrics[timestamp]>=All_Hours))" 非常感谢您的帮助。
解决方案
您想计算从现在开始的 7 天的 AVERAGE 吗?或者在每个 DateTime 结束的最后 7 天?
AVG7dayNOW =
Calculate (AVERAGE(Table1[Quantity]), FILTER(ALL(Table1[DateTime]), Table1[DateTime] >= NOW() - 7 && Table1[DateTime] <= NOW()))
第二击:
AVG7Day =
calclulate (AVERAGE(Table1[Quantity]), FILTER(ALL(Table1[DateTime]), Table1[DateTime] >= SELECTEDVALUE(Table1[DateTime]) - 7 && Table1[DateTime] <= SELECTEDVALUE(Table1[DateTime])))
如果要应用其他过滤器,可以将 ALL 更改为 ALLSELECTED。
推荐阅读
- c++ - 删除多个 _mm256_blend_ps 会降低性能而不是提高性能
- python - python数据库结果不适用于if语句
- python-3.x - 具有字符串和整数元组键的字典上的 Python 数值运算
- c++ - 带有结构“未声明的标识符”的 C++ 类
- r - 根据不同列但同一行中的值识别一列中的值
- android - 我的适配器似乎正在接收数据,但它没有显示在我的 RecyclerView 中。关于我做错了什么的任何想法?
- javascript - 如何在 gatsby 中使用 citation.js 将 bibtext 条目呈现到 HTML 书目?
- html - 我正在尝试使用 css 为向上箭头和带有动画的向下箭头创建 svg 箭头,但无法制作向上箭头
- linux - 如何在前一个作业完成后运行 sbatch 作业?
- python - 无法更改python中变量的值,if-statement