DAX 计算所有 7 天数量值的平均值
DAX to calculate the average for all 7 days Quantity value
| 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 天的平均值吗?或者每个日期时间结束的最后 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。
| 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 天的平均值吗?或者每个日期时间结束的最后 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。