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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
James__
Frequent Visitor

Rolling average same period last year

Hi,

 

I have a rolling average measure which works as it should: 

@rolling_avg_sales_per_day = AVERAGEX(FILTER(ALLSELECTED('Calendar'),'Calendar'[Date]<=MAX('Calendar'[Date])),[@@@product_sales])
 
James___0-1669804015112.png

 

 
I then try and look for the same rolling average for the same period last year, but not getting the desired result. I have tried 2 measures without success:
1. 
@rolling_avg_sales_per_day_SPLY = CALCULATE([@rolling_avg_sales_per_day],SAMEPERIODLASTYEAR('Calendar'[Date]))
2. 
@rolling_avg_sales_per_day_SPLY = CALCULATE([@rolling_avg_sales_per_day],DATEADD('Calendar'[Date],-1,YEAR))
 
instead i am getting this:
 
James___1-1669804054123.png

 

 

Can anyone help with the correct measure, please?

 

Thanks

James 

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @James__ ,

 

According to your description, here are my steps you can follow as a solution.

You can create a measure as below:

 

 

Sales R12M = 
VAR NumOfMonths = 12
VAR LastCurrentDate =
    MAX ( 'Date'[Date] )
VAR Period =
    DATESINPERIOD ( 'Date'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Date'[YearMonth]),
            [Sales Amount]
        ),
        Period
    )
VAR FirstDateInPeriod = MINX ( Period, 'Date'[Date] )
VAR LastDateWithSales = MAX ( Sales[Order Date] )
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 

 

Then the result is as follows.

vtangjiemsft_0-1669864800164.png

You can refer to the following documents that may be helpful to you:

Rolling 12 Months Average in DAX - SQLBI

Solved: Rolling 12M Average only calculate average on year... - Microsoft Power BI Community

Cumulative rolling average by day/month - Microsoft Power BI Community

Solved: Need help with rolling periods past 12M, 6M, P3M a... - Microsoft Power BI Community

 

Best Regards,

Neeko Tang

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

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @James__ ,

 

According to your description, here are my steps you can follow as a solution.

You can create a measure as below:

 

 

Sales R12M = 
VAR NumOfMonths = 12
VAR LastCurrentDate =
    MAX ( 'Date'[Date] )
VAR Period =
    DATESINPERIOD ( 'Date'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Date'[YearMonth]),
            [Sales Amount]
        ),
        Period
    )
VAR FirstDateInPeriod = MINX ( Period, 'Date'[Date] )
VAR LastDateWithSales = MAX ( Sales[Order Date] )
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 

 

Then the result is as follows.

vtangjiemsft_0-1669864800164.png

You can refer to the following documents that may be helpful to you:

Rolling 12 Months Average in DAX - SQLBI

Solved: Rolling 12M Average only calculate average on year... - Microsoft Power BI Community

Cumulative rolling average by day/month - Microsoft Power BI Community

Solved: Need help with rolling periods past 12M, 6M, P3M a... - Microsoft Power BI Community

 

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors