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.
I have created a calculated table that contains two fields: a date (no time), and a numerical value for each date.
It looks something like this:
I am trying to get a running average of the previous 30 days for each date. I have tried the following columns:
DIVIDE( CALCULATE( SUM(DaySum[Cargo Tonnes]), DATESBETWEEN( 'DaySum'[Date], DATEADD('DaySum'[Date],-30,DAY), 'DaySum'[Date] ) ),30)
AND
DIVIDE( CALCULATE( SUM(DaySum[Cargo Tonnes]), DATESINPERIOD ( 'DaySum'[Date], DaySum[Date],-30,DAY )),30)
AND
DIVIDE( CALCULATE( SUM(DaySum[Cargo Tonnes]), DATESBETWEEN( DaySum[Date], FIRSTDATE(DATEADD(DaySum[Date],-30,DAY)), LASTDATE(DaySum[Date]) ) ),30)
But the result is always the [Cargo Tonnes] field divided by 30. It never seems to SUM the preceeding 30 days, then divide that sum by 30, thus:
Can anyone suggest where I might be going wrong?
Thanks!
Tom.
Solved! Go to Solution.
Hey Tom,
By including a filter, ALL(DaySum), you will achieve the results you are looking for. See below for an example.
30 Day Average = DIVIDE( CALCULATE( SUM(DaySum[Cargo Tonnes]), ALL(DaySum), DATESBETWEEN(DaySum[Date], LASTDATE(DaySum[Date])-30, LASTDATE(DaySum[Date])) ) ,30)
Hey Tom,
By including a filter, ALL(DaySum), you will achieve the results you are looking for. See below for an example.
30 Day Average = DIVIDE( CALCULATE( SUM(DaySum[Cargo Tonnes]), ALL(DaySum), DATESBETWEEN(DaySum[Date], LASTDATE(DaySum[Date])-30, LASTDATE(DaySum[Date])) ) ,30)
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 |
---|---|
17 | |
9 | |
8 | |
7 | |
7 |