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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
manojbariki1987
New Member

Dax for Last 6 months Rolling average

Hi Everyone,

Could anyone please help me with Dax for the last 6 months rolling average and it has to be dynamic as selection with months.

Early responses are highly appreciated.

 

Thanks & Regards

Manoj

 

 

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

Hi @manojbariki1987 ,

Using Calculation Groups:

  • Calculation groups allow you to dynamically switch measures based on slicer selections. In your case, we’ll create a calculation group to handle the rolling average.

  • Here are the steps:

    • Create a New Table:

      • First, create a new table called “Previous Date.” This table will be independent of slicer filters.
      • You can copy the existing Date table to create this new table: .Previous Date = 'Date' Copy
    • Link the Tables:

      • Create an inactive relationship between the Date table and the Previous Date table. This ensures that the filter won’t propagate from the slicer to the Previous Date table.
    • Write a DAX Measure:

      • Define a measure that calculates the rolling average for the last 6 months.
      • For example, if your measure is called “Sales Amount,” the DAX code might look like this:
Rolling Average = 
VAR SelectedDate = MAX('Date'[Date])
VAR RollingMonths = DATESINPERIOD('Previous Date'[Date], LASTDATE('Date'[Date]), -6, MONTH)
VAR AvgSales = AVERAGEX(RollingMonths, [Sales Amount])
RETURN IF(HASONEVALUE('Date'[Month]), AvgSales, BLANK())

Best Regards,

Xianda 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

2 REPLIES 2
v-xiandat-msft
Community Support
Community Support

Hi @manojbariki1987 ,

Using Calculation Groups:

  • Calculation groups allow you to dynamically switch measures based on slicer selections. In your case, we’ll create a calculation group to handle the rolling average.

  • Here are the steps:

    • Create a New Table:

      • First, create a new table called “Previous Date.” This table will be independent of slicer filters.
      • You can copy the existing Date table to create this new table: .Previous Date = 'Date' Copy
    • Link the Tables:

      • Create an inactive relationship between the Date table and the Previous Date table. This ensures that the filter won’t propagate from the slicer to the Previous Date table.
    • Write a DAX Measure:

      • Define a measure that calculates the rolling average for the last 6 months.
      • For example, if your measure is called “Sales Amount,” the DAX code might look like this:
Rolling Average = 
VAR SelectedDate = MAX('Date'[Date])
VAR RollingMonths = DATESINPERIOD('Previous Date'[Date], LASTDATE('Date'[Date]), -6, MONTH)
VAR AvgSales = AVERAGEX(RollingMonths, [Sales Amount])
RETURN IF(HASONEVALUE('Date'[Month]), AvgSales, BLANK())

Best Regards,

Xianda Tang

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

Daniel29195
Super User
Super User

@manojbariki1987 

create w dimdate table . 

link it to your fact. 

 

check this article. would help you . 

https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/

 

let me know this works for you. 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.