Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi, I am trying to create 3months back rolling average with filter, becaue it needs to be rolling average per Plant. What I have created (or edited) below.
*The table I'm working on was created with the Summarize function
Total COGS | FixedDate | Plant | 3monthsRollingAverage |
2 | 01/01/2020 | 1 | |
3 | 02/01/2020 | 1 | |
2 | 03/01/2020 | 1 | 2.33333 |
5 | 04/01/2020 | 1 | 3.33333 |
4 | 01/01/2020 | 2 | |
2 | 02/01/2020 | 2 | |
3 | 03/01/2020 | 2 | 3 |
3 | 04/01/2020 | 2 | 4 |
Solved! Go to Solution.
Hi @arutsjak90 -
Make sure you have a calendar table, linked to the "Fixed Date" column in your table, and then try this code
Rolling 3 Mo Avg =
VAR __ThisMonth =
MAX ( COGS[FixedDate] )
VAR __3MoBack =
EDATE ( __ThisMonth, -3 ) + 1
RETURN
CALCULATE (
SUM ( COGS[Total COGS] ),
ALLEXCEPT ( COGS, COGS[Plant] ),
DATESBETWEEN ( DateTab[Date], __3MoBack, __ThisMonth )
) / 3
Hope this helps
David
Hi @arutsjak90 -
Make sure you have a calendar table, linked to the "Fixed Date" column in your table, and then try this code
Rolling 3 Mo Avg =
VAR __ThisMonth =
MAX ( COGS[FixedDate] )
VAR __3MoBack =
EDATE ( __ThisMonth, -3 ) + 1
RETURN
CALCULATE (
SUM ( COGS[Total COGS] ),
ALLEXCEPT ( COGS, COGS[Plant] ),
DATESBETWEEN ( DateTab[Date], __3MoBack, __ThisMonth )
) / 3
Hope this helps
David
Thank you for your time, but it is not working..
after entering this code, I get the sum of the whole Total COGS column divided by 3, not splited into plants and not rolling, very strange
You need to create it as a measure, not as a column.
Thanks, but still the same result
Please share a copy of your pbix with sensitive data removed. Dropbox, Google Drive, OneDrive, GitHub, etc.
I have sent it via private message
Please post the link in the thread, not PM, in case others want to look at it or help.
That being said, you did not create the proper relationships in your model, as instructed. This will cause the measure code to not work correctly.
Link "COSG[Fixed Date]" to DateTab[Date].
Hope this helps
David
https://drive.google.com/drive/folders/16GoTloQOeYLuvgu6eMl6M0LSgKA4iJzj?usp=sharing
Thank you!
Is it possible to create calculated column instead of measure?
I would not recommend creating it as a calcaulted column. Measures can be used in mostly the same way as columns and are more dynamic.
If you run into an issue using the measure in further calculations, please start a new thread instead of continuing this one.
David
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
9 | |
8 | |
8 |
User | Count |
---|---|
14 | |
12 | |
11 | |
11 | |
8 |