Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

3 months rolling average value

I am trying to get the average values for previous month, current month and the next month... and I am using this formula but for some reason 3 months rolling average values are wrong   This valu...
  • muhammad_786_1's avatar
    1 year ago

    Hi Anonymous 

     

    You can make a few modifications to your DAX formula, and it should work correctly for you. I have also compared the results, which you can see in the attached screenshot and Power BI file for verification.

     

    3MonthRollingAverage = 
    VAR CurrentDate = MIN('175HPTractors'[DATESEEN])
    VAR StartDate = DATE(YEAR(CurrentDate), MONTH(CurrentDate) - 2, 1) -- StartDate of previous month
    VAR EndDate = EOMONTH(CurrentDate, 1) -- EndDate of next month
    RETURN
        CALCULATE(
            AVERAGE('175HPTractors'[PRICE]),
            FILTER(
                ALL('175HPTractors'),
                '175HPTractors'[DATESEEN] >= StartDate &&
                '175HPTractors'[DATESEEN] <= EndDate
            )
        )

     

    File

     

    Best Regards,
    Muhammad Yousaf

     

    If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

     

    LinkedIn

     

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Anonymous 

    You can use the DATESINPERIOD function, which returns the date of the period:

    rolling average = CALCULATE(
    AVERAGE('Table'[value]),
    DATESINPERIOD(
    'Table'[Date],
    MAX('Table'[Date]),
    -3,
    MONTH
    )
    )

     

     

     

     

     

    Best Regards,

    Jayleny

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.