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 facing calculation issue in Rolling 4 Week Average;
Margin (Measure)
Rolling 4 Wk Average (Measure)
Solved! Go to Solution.
Hi @apatwal
Here's the answer
Margin 4 Week Rolling Average =
VAR RelevantWeeks =
CALCULATETABLE(
VALUES('Calendar'[WeekEndingDate]),
DATESBETWEEN(
'Calendar'[Date],
MAX('Calendar'[Date]) - 28,
MAX('Calendar'[Date])
),
REMOVEFILTERS('Calendar')
)
RETURN
AVERAGEX(
RelevantWeeks,
[Total Margin]
)
Hi @apatwal I'm not understanding why you're ranking weeks as part of this calculation. If you have a date table (and you do) and it is marked as one, your calculation should be fairly simple unless I'm missing something?
VAR RelevantWeeks =
CALCULATETABLE(
VALUES(DateTable[Week End Date]),
DATESBETWEEN(
DateTable[Date],
MAX(DateTable[Date]) - 28,
MAX(DateTable[Date])
)
)
RETURN
AVERAGEX(
RelevantWeeks,
[Margin]
)
I had decided not to reply earlier but then you are demonstrating today what you condemed yesterday?
So, yesterday you wrote:
"you posted your response an hour after I did. I've noticed you doing this on multiple posts in the last couple weeks, both to me and to others. There's an expectation of etiquette in the forum, where we try not to overwhelm the users with numerous responses. Because all it does is create confusion. It would be appreciated if you followed etiquette.
Then today your reply today (I'm meassge #2 and you are message#3,came after my reply on this topic. My reply was correct. If you read it you would know this question was answered to the point of a minor tweak ,based on the users reply. And to avoid confusion I let you run with it for many replies.
The point here is that on occasion, multiple people may be wokring on a solution for others. After spending time on a working solution, it is not always realistic to read or even see others replies. As I explained earlier to you, that none of this is purposeful or ego driven on my side. I also believe the question when solved is noted but until then others can try to help. Some questions have many replies by more than one person in the spirit of aiding another.
I have seen you jump in on others replies, but did't think this behavior correction should be aired or corrected openly, like you choose to do. Then the very next day you do the same with me on this topic.
The goal here is to help others, offer sugestions and I'm sorry if you feel you are the only one who can participate once you decide you want to reply.
You are the only one here pointing out your issues.
Sorry I missed out the screenshots.
Looks like may be I am missing something:
Thanks...
Hi @apatwal you're not having it average anything. After the closing parenthesis for DATESBETWEEN, add a comma and then [Margin] (or the name of your measure). That should take care of it
Thanks for your reply!
Ooops that was my small mistake..
But Now I am facing another issue
Its now giving me nothing...
using below DAX
and using below DAX, I am getting wrong values...
Hi @apatwal
Here's the answer
Margin 4 Week Rolling Average =
VAR RelevantWeeks =
CALCULATETABLE(
VALUES('Calendar'[WeekEndingDate]),
DATESBETWEEN(
'Calendar'[Date],
MAX('Calendar'[Date]) - 28,
MAX('Calendar'[Date])
),
REMOVEFILTERS('Calendar')
)
RETURN
AVERAGEX(
RelevantWeeks,
[Total Margin]
)
Your DAX is also giving me same result; there is no change is result.
Could you help me on this?
Looks like there are issues in your DAX, I could not understand...
Hello:
One way to address is by using DATESINPERIOD but using 28 days. It will work in a weekly grid.
Margin MA 4 weeks =
var _currentdate = MAX('Date Table'[Date])
Margin MA 4 weeks =
IF(
VAR daybegin = CALCULATE(FIRSTDATE('Table Date'[Date]), ALLSELECTED('Table Date'[Date]))
VAR add28 = daybegin + 28
VAR _measure =
IF(MAX('Calendar'[Date Description]) >= add28, _measure, BLANK())
I hope this can work for you.
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 |