Forum Discussion

PaulBI's avatar
PaulBI
Frequent Visitor
7 years ago
Solved

Problems getting previous month averages

I have one table (Overtime) with Activity_date and Activity_hours.  I have a date table (Date) which has a relationship between activity_date and the date column of the date table.  I am trying to fi...
  • Stachu's avatar
    Stachu
    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!