Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi guys
I am quite new to Power BI and I am struggling now with getting the value from the second latest date. So i have a table "Gesamt" like the following
| Name Code | Datum | Gewicht | DIFFDate |
| Person 1 | 15.01.2024 | 88 | 31 |
| Person 1 | 16.01.2024 | 89 | 30 |
| Person 1 | 17.01.2024 | 87 | 29 |
| Person 1 | 18.01.2024 | 88.5 | 28 |
| Person 1 | 19.01.2024 | 89.5 | 27 |
| Person 1 | 20.01.2024 | 87.5 | 26 |
| Person 2 | 21.01.2024 | 60.5 | 25 |
| Person 2 | 22.01.2024 | 60 | 24 |
| Person 2 | 23.01.2024 | 61 | 23 |
| Person 2 | 24.01.2024 | 59.5 | 22 |
| Person 2 | 15.01.2024 | 59 | 31 |
| Person 3 | 13.01.2024 | 70 | 33 |
| Person 3 | 14.01.2024 | 71 | 32 |
| Person 3 | 15.01.2024 | 69 | 31 |
| Person 3 | 16.01.2024 | 69.5 | 30 |
| Person 3 | 17.01.2024 | 70.5 | 29 |
| Person 3 | 18.01.2024 | 71.5 | 28 |
| Person 3 | 24.01.2024 | 72 | 22 |
I calculated the newest value of "Gewicht* with
//Try this
DifferenceSecondLatestLast =
VAR LatestRank = RANKX(ALL(Gesamt), CALCULATE(AVERAGE(Gesamt[DIFF Date])))
VAR SecondLatestRank = LatestRank - 1
RETURN
CALCULATE(
AVERAGE(Gesamt[Gewicht]),
FILTER(ALL(Gesamt), Rank IN {LatestRank, SecondLatestRank})
) -
CALCULATE(
AVERAGE(Gesamt[Gewicht]),
Rank = LatestRank
)
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
Hi
if I try this, I got an error message (as in the picture).
Even if I put the "Rank" in [ ] to define it's the measure, it's not working.
Also the "Latest Rank" does not define the latest rank, right? IS there a "Max" missig?
Thanks
You can add visual filter it works with measures and put the rank measure value to 2
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
Thanks Muhammad for your reply.
As I mentioned I want to calculate in another step with the second latest value (at the end it's the difference between the latest and the second latest). So only by filtering the visual it won't work. Or am I thinking in a wrong way?
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 39 | |
| 37 | |
| 33 | |
| 32 | |
| 29 |
| User | Count |
|---|---|
| 132 | |
| 88 | |
| 82 | |
| 68 | |
| 64 |