0

I have a challenge in power BI to calculate average YTD.

enter image description here

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

1 Answers1

1

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:

YTD-Table

Hope this helps. Please don't hesitate to ask if you have further questions.

OscarLar
  • 1,315
  • 1
  • 5
  • 15
  • Thank you Oscar, I did managed to resolve the issue. Something was broken in my relationships. So, i resolved using Alexis function. But, great to have multiple ways. Thank you so much. :) – Mahmoud Samir Mar 26 '19 at 10:56