Forum Discussion
Calculate average last value in Power BI
| CustomerCode | Date | Value |
| 100 | 03.06.2022 | 70,0 |
| 101 | 14.06.2022 | 97,8 |
| 103 | 02.06.2022 | 89,0 |
| 109 | 10.06.2022 | 80,7 |
| 108 | 24.05.2022 | 72,8 |
| 106 | 24.05.2022 | 83,2 |
| 104 | 16.05.2022 | 96,2 |
| 114 | 20.05.2022 | 65,9 |
| 114 | 01.06.2022 | 87,3 |
| 120 | 19.05.2022 | 97,1 |
| 119 | 13.06.2022 | 61,7 |
I want to have 87.3 for customer 114. And then calculate the average of all values. In SQL I would use Rank () over (partition by customercode order by date desc) and then choosing rank =1 and an average on top of that. But I don't know how to do this in DAX.
Please note that in the final report the end user can put year-quarter or year-month instead of daily date but he should be able to see the average of last value in the quarter or the month.
I have tried multiple ways but not succeeded. Any help would be much appreciated.
5 Replies
- Ahmedx
Super User
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
- lucadelicio
Impactful Individual
it doesn't work
- lucadelicio
Impactful Individual
Your request are not clear.
In the pbix there yet the solution of the latest value for the customer code.
This measure calculate the avg for customer code:Measure =AVERAGEX(VALUES('Table'[CustomerCode]),AVERAGE('Table'[Value]))
If you are more specific with your request i will help you.
Thank you
- lucadelicio
Impactful Individual
Can you share a pbix with the sample data in?
- lucadelicio
Impactful Individual
Anonymous have you got some news?
Thank you