Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hello Everyone,
This is my first post, so i hope I will match all requirements.
I have a data set with 4 columns:
Market: multiple countries
Date: 1st day of month, used mostly for Month & Year combination
KPI: multiple KPI names
Value: Value for KPI
I cannot edit thing in Power Query.
My aim is to get Rolling Average for each month, but not showing last "X" months but period of time from past.
As Example:
July 2023 - Averagex between March 2023 and May 2023
June 2023 - Averagex between February 2023 and April 2023
Moreover time period should be editable, so VAR is set in a way that I can change one number (let's say -2 to -3 and whole calculation changes)
Can you point me into right direction. Everything I found or wrote was for "X" last months.
Thank you in advance for help.
@Pawel_1990 So you should be able to do something like the following (this assumes a bunch of stuff like you have your KPI and country in context, etc via slicer or within the visual or whatever.
Measure =
VAR __MonthsBack = -4
VAR __Months = 3
VAR __Date = MAX('Table'[Date])
VAR __StartMonth = EOMONTH( __Date, __MonthsBack)
VAR __MinDate = DATE( YEAR( __StartMonth ), MONTH( __StartMonth ), 1 )
VAR __MaxDate = EOMONTH( __MinDate, 3 )
VAR __Table = FILTER( 'Table', [Date] >= __MinDate && [Date] <= __MaxDate )
VAR __Result = AVERAGEX( __Table, [Value] )
RETURN
__Result
thank you for help. You gave me correct approach for this one.
Two questions showed up.
#1. When execute this one line of code I get date in 19XX. When executing each part of code sepratly, for example: Year(__StartMonth) I get correct numbers. Any idea what's happening?
VAR __MinDate = DATE( YEAR( __StartMonth ), MONTH( __StartMonth ), 1 )
#2- I think here VAR __Months should be used instead "3". Am I correct?
VAR __MaxDate = EOMONTH( __MinDate, 3 )
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 9 | |
| 9 | |
| 8 | |
| 6 | |
| 5 |
| User | Count |
|---|---|
| 23 | |
| 16 | |
| 15 | |
| 14 | |
| 8 |