I have a challenge in power BI to calculate average YTD.
I am looking for make the average for month two take in consideration data from month one and so on.
Any idea how to do that in Power BI?
Thank you in advance, Mahmoud
I have a challenge in power BI to calculate average YTD.
I am looking for make the average for month two take in consideration data from month one and so on.
Any idea how to do that in Power BI?
Thank you in advance, Mahmoud
Not knowing why the solution by Alexis didn't work for you, I've made the assumption that you only have one table (called 'Data'), with two columns as your image showed.
Step one: Add two new columns (if you do this in Power query or power bi doesn't matter): [Month_name] and [Month_number].
[Month_Name] = FORMAT([Date]; "MMM")
[Month_number] = MONTH([Date])
Step two: Add a measure
YTD Avg =
var currentMonth = MAX([Month_number])
RETURN
DIVIDE(
CALCULATE
SUM(Data[Amount]);
ALL(Data[Month_Name]);
Data[Month_number] <= currentMonth
);
CALCULATE(
COUNTROWS(DATA);
ALL([Month_Name]);
Data[Month_number] <= currentMonth
);
0
)
This should generate the following table:
Hope this helps. Please don't hesitate to ask if you have further questions.