Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
AA622
Helper II
Helper II

Rolling yearly Average

Hello

 

I am trying to calculate a rolling average. Its to calculate the yearly usage of a certain product over the last rolling 12 months and then from there I will calculate the daily average by working days (#260). 

 

I was using this formula but it doesnt match the actual yearly usage based on historical data.

UsageRollingYearly = CALCULATE(
    [Usage],
    DATESINPERIOD(
        'Calendar'[Date],
        MAX('Calendar'[Date]),
        -365,DAY))
 

I have another formula but I also cant seem to get it 100% right across all products

Usage12mo = CALCULATE (
[Usage],
FILTER ( ALL ( 'Calendar' ),
'Calendar'[Date] >= TODAY() - 365))
 
My question is which formula is more indicative of an accurate measure to calculate rolling 12 months usage?
 
Whatever number is calculated from either of these measures will be used to calculate daily average.
1 ACCEPTED SOLUTION

Hi @AA622 ,

Please update the formula of your measure [UsageRolling6mo] as below and check if it works or not...

UsageRolling6mo =
VAR __MaxDate =
    TODAY ()
VAR __EOM12 =
    EOMONTH ( __MaxDate, -12 )
VAR __MinDate =
    DATE ( YEAR ( __EOM12 ), MONTH ( __EOM12 ), DAY ( __MaxDate ) )
VAR __Table =
    FILTER (
        ALLSELECTED ( 'Calendar' ),
        'Calendar'[Date] <= __MaxDate
            && 'Calendar'[Date] >= __MinDate
    )
RETURN
    AVERAGEX ( __Table, [Usage] )

In addition, you can refer the following links to get the rolling average values:

Rolling Averages In Power BI

yingyinr_1-1665394209343.png

Rolling 12 Months Average in DAX

Best Regards

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

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@AA622 Try:

 

Better RA =
    VAR __MaxDate = TODAY() 
    VAR __EOM12 = EOMONTH(__MaxDate,-12)
    VAR __MinDate = DATE(YEAR(__EOM12),MONTH(__EOM12),DAY(__MaxDate)
    VAR __Table = FILTER(ALLSELECTED('Table'),[Date] <= __MaxDate && [Date] >= __MinDate)
RETURN
    AVERAGEX(__Table,[Usage])

 

Both of the formulas you have currently are equally bad in my opinion because they do not account for leap years.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Better RA =
    VAR __MaxDate = TODAY() 
    VAR __EOM12 = EOMONTH(__MaxDate,-12)
    VAR __MinDate = DATE(YEAR(__EOM12),MONTH(__EOM12),DAY(__MaxDate)
    VAR __Table = FILTER(ALLSELECTED('Table'),[Date] <= __MaxDate && [Date] >= __MinDate)
RETURN
    AVERAGEX(__Table,[Usage])

 

HAving issues with the last VAR line. Line 5

 

Am I supposed to reference a table?

AA622_0-1665090504100.png

 

I tried referencing our Calendar Table. What would I put at the last line? I also seem to be having an issue with the mindate VAR in line 5

Hi @AA622 ,

Please update the formula of your measure [UsageRolling6mo] as below and check if it works or not...

UsageRolling6mo =
VAR __MaxDate =
    TODAY ()
VAR __EOM12 =
    EOMONTH ( __MaxDate, -12 )
VAR __MinDate =
    DATE ( YEAR ( __EOM12 ), MONTH ( __EOM12 ), DAY ( __MaxDate ) )
VAR __Table =
    FILTER (
        ALLSELECTED ( 'Calendar' ),
        'Calendar'[Date] <= __MaxDate
            && 'Calendar'[Date] >= __MinDate
    )
RETURN
    AVERAGEX ( __Table, [Usage] )

In addition, you can refer the following links to get the rolling average values:

Rolling Averages In Power BI

yingyinr_1-1665394209343.png

Rolling 12 Months Average in DAX

Best Regards

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

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.