Forum Discussion
Problems getting previous month averages
- 7 years ago
I'd use the Date table to modify the date filter context
so e.g. if this is your average:Avg = CALCULATE ( DIVIDE ( SUM ( Overtime[Activity_Hours] ), DISTINCTCOUNT ( 'Overtime'[Activity_Date] ), 0 ), KEEPFILTERS(WEEKDAY ( 'Calendar'[Date], 2 ) > 5) )you can calculate previous month average like this:
Avg Prev Month = CALCULATE( [Avg], PREVIOUSMONTH('Calendar'[Date]) )which calculated the period in reference to the filter context in the Calendar table (here row determines specific month):
you can notice that [Avg Prev Month] is empty on total - that's because there is no specific month reference
Did I answer your question? Mark my post as a solution!
Proud to be a Datanaut!
Below is the graphic I'm trying to create, where the projected is using last month's average # of hours per weekday and weekend to project to the end of the month. Right now the projection is being calculated by the measure 'Projected" (below) which uses the calculated column in the dates table in the picture in my earlier post (Date[Forecast]) but like I said, it is not actually relaying the true previous month average. All the help so far is really appreciated. If you have any insight into how better to do this would be appreciated too. Thanks!
Projected =
if(SELECTEDVALUE('Date'[Dateswithdata])=FALSE(),calculate(sum(Overtime[Activity_Hours])+(sum('Date'[Forecasted])),DATESMTD('Date'[Date]),year('Date'[Date])>=year(TODAY()),month('Date'[Date])=month(today())),BLANK())Stachu
Thank you for all the help. I really appreciate it.
After a bunch of trial and error I think I figured out the overall solution. I took the dax from the calculated column, shifted from a sum to a sumx and pasted all of it in the measure where I had the calculated column. It looks like this:
Projected =
if(SELECTEDVALUE('Date'[Dateswithdata])=FALSE(),calculate(sum(Overtime[Activity_Hours])+(sumx('Date',if('Date'[Dateswithdata]=false,if('Date'[Weekend?]=true,[Last Month Average Monthly Weekend Day Hours],[Last Month Average Monthly Weekday Hours]),BLANK()))),DATESMTD('Date'[Date]),year('Date'[Date])>=year(TODAY()),month('Date'[Date])=month(today())),BLANK())- Stachu7 years ago
Community Champion
glad you got it working :smileyhappy: