March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi all,
I need your help.
I am stuck in a DAX problem, my scenairio is
I have a date table and I have a project table with some score. I want to calculate moving average of 6 months of that score. The problem is in project table period first doesn't have data from past, so from start period upto month 5 there will be average of only available data period. i.e. in first period average will be just that month, in 2nd period average will be just for 2 months that is period one and two, that will go up to period 5. So there will be only complete six month average in period 6. Currently, my calculation is doing average even in first peried it is dividing first period score by 6, which is wrong and the average score get two low. Also I want only last twelve month display in the chart, currently I can't control it. Required correct data sample is below.
FISCAL period from Project table | Score | 6 months moving average |
1/01/2024 | 10 | 10 |
1/02/2024 | 12 | 11 |
1/03/2024 | 8 | 10 |
1/04/2024 | 12 | 10.5 |
1/05/2024 | 14 | 11.2 |
1/06/2024 | 9 | 10.83 |
1/07/2024 | 12 | 11.17 |
1/08/2024 | 11 | 11 |
1/09/2024 | 8 | 11 |
1/10/2024 | 13 | 11.17 |
1/11/2024 | 9 | 10.33 |
1/12/2024 | 10 | 10.5 |
1/01/2025 | 11 | 10.33 |
I have deadline
Please help in this regard.
Regards,
Jag
Solved! Go to Solution.
Hi @JJha75 ,
There are many ways to produce your required output, and one of them is by creating a calculated column like below:
Moving average (6 months) =
VAR EndDate = 'Table'[FISCAL period from Project table]
VAR StartDate = EOMONTH(EndDate, -6) + 1
VAR Cumulative_Score =
CALCULATE(
SUM('Table'[Score]),
'Calendar'[Date] <= EndDate &&
'Calendar'[Date] >= StartDate
)
VAR Number_of_Months =
CALCULATE(
COUNTROWS('Table'),
'Calendar'[Date] <= EndDate &&
'Calendar'[Date] >= StartDate
)
RETURN
IF(
Number_of_Months > 0,
divide(Cumulative_Score , Number_of_Months),
BLANK()
)
The resultant output matches with your required output:
Best regards,
Hi @JJha75 ,
There are many ways to produce your required output, and one of them is by creating a calculated column like below:
Moving average (6 months) =
VAR EndDate = 'Table'[FISCAL period from Project table]
VAR StartDate = EOMONTH(EndDate, -6) + 1
VAR Cumulative_Score =
CALCULATE(
SUM('Table'[Score]),
'Calendar'[Date] <= EndDate &&
'Calendar'[Date] >= StartDate
)
VAR Number_of_Months =
CALCULATE(
COUNTROWS('Table'),
'Calendar'[Date] <= EndDate &&
'Calendar'[Date] >= StartDate
)
RETURN
IF(
Number_of_Months > 0,
divide(Cumulative_Score , Number_of_Months),
BLANK()
)
The resultant output matches with your required output:
Best regards,
For your reference.
MOVINGAVERAGE function (DAX) - DAX | Microsoft Learn
Using visual calculations in Power BI Desktop - Power BI | Microsoft Learn
Calculation = MOVINGAVERAGE([Sum of Score],6,ROWS)
Thanks Mickey.
This is exactly the calculation I am looking for but not in the table, I want the same calculation in measure to use in chart. If you could find me the logic how that moving average works then I can use it in the Line & clustered column chart.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
129 | |
90 | |
75 | |
58 | |
53 |
User | Count |
---|---|
200 | |
104 | |
101 | |
67 | |
55 |