我正在做类似的事情:Calculate Running Average Using DAX in Power BI
唯一的区别如下:
期望的输出:
date sales_amount desired_running_average
04/01/2021 100.00 100.00
04/02/2021 300.00 200.00
04/05/2021 500.00 300.00
目前在做什么:
date sales_amount desired_running_average
04/01/2021 100.00 100.00
04/02/2021 300.00 300.00
04/05/2021 500.00 500.00
Total desired_running_average: 300.00
I'm not sure why my code gives it to me on the total instead of row by row.
我有以下代码:
running_average_code_I_am_using =
VAR FirstVisibleDate = CALCULATE(MIN('d_Date'[Date]),ALLSELECTED('d_Date'[Date]))
VAR LastVisibleDate = CALCULATE(MAX('d_Date'[Date]),ALLSELECTED('d_Date'[Date]))
VAR LastDateWithSales =
CALCULATE(
CALCULATE(MAX(Table_1[date]),ALLSELECTED(Table_1[date]))
,REMOVEFILTERS()
)
VAR Result =
IF (
FirstVisibleDate <= LastDateWithSales,
CALCULATE(
AVERAGE(Table_1[sales_amount])
,Table_1[date] <= LastVisibleDate
)
)
RETURN
Result