Forum Discussion
TsW08
2 years agoNew Member
Month plus month average
Hi, I have a table in Power Bi with all our staff, and costings. The tsblr has a "Date" column, as well as "Year", "Month" & "Quarter" and then a "Cost" column. I have been looking for a way...
- Anonymous2 years ago
Thanks for your prompt reply! bhanu_gautam
Hi TsW08Based on your needs, I have created the following table.
Then you can try the following dax to get "total cost", "average between two months", "average divide by 12".
Total = VAR _month = SELECTEDVALUE('Table'[Month]) VAR _year = SELECTEDVALUE('Table'[Year]) RETURN CALCULATE(SUM('Table'[Cost]),FILTER(ALL('Table'),'Table'[Year]=_year && 'Table'[Month]=_month))Average = VAR _month = SELECTEDVALUE('Table'[Month]) VAR _year = SELECTEDVALUE('Table'[Year]) VAR _current = CALCULATE([Total],FILTER(ALL('Table'),'Table'[Year] = _year && 'Table'[Month] = _month)) VAR _previous = CALCULATE([Total],FILTER(ALL('Table'),'Table'[Year] = _year && 'Table'[Month] = _month - 1)) RETURN IF(_previous = BLANK(),[Total],(_current + _previous)/2)average and divide by 12 = var _year = SELECTEDVALUE('Table'[Year]) RETURN SUMX(FILTER(ALL('Table'),'Table'[Year]=_year),'Table'[Average])/12
Result:Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
2 years agoNot applicable
Thanks for your prompt reply! bhanu_gautam
Hi TsW08
Based on your needs, I have created the following table.
Then you can try the following dax to get "total cost", "average between two months", "average divide by 12".
Total =
VAR _month = SELECTEDVALUE('Table'[Month])
VAR _year = SELECTEDVALUE('Table'[Year])
RETURN
CALCULATE(SUM('Table'[Cost]),FILTER(ALL('Table'),'Table'[Year]=_year && 'Table'[Month]=_month))
Average =
VAR _month = SELECTEDVALUE('Table'[Month])
VAR _year = SELECTEDVALUE('Table'[Year])
VAR _current = CALCULATE([Total],FILTER(ALL('Table'),'Table'[Year] = _year && 'Table'[Month] = _month))
VAR _previous = CALCULATE([Total],FILTER(ALL('Table'),'Table'[Year] = _year && 'Table'[Month] = _month - 1))
RETURN IF(_previous = BLANK(),[Total],(_current + _previous)/2)
average and divide by 12 =
var _year = SELECTEDVALUE('Table'[Year])
RETURN
SUMX(FILTER(ALL('Table'),'Table'[Year]=_year),'Table'[Average])/12
Result:
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.