Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

second latest value

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 CodeDatumGewicht

DIFFDate

Person 115.01.20248831
Person 116.01.20248930
Person 117.01.20248729
Person 118.01.202488.528
Person 119.01.202489.527
Person 120.01.202487.526
Person 221.01.202460.525
Person 222.01.20246024
Person 223.01.20246123
Person 224.01.202459.522
Person 215.01.20245931
Person 313.01.20247033
Person 314.01.20247132
Person 315.01.20246931
Person 316.01.202469.530
Person 317.01.202470.529
Person 318.01.202471.528
Person 324.01.20247222

 

I calculated the newest value of "Gewicht*  with 

 

GEWakt = CALCULATE(AVERAGE(Gesamt[Gewicht]),Gesamt[DIFF Date]=MIN(Gesamt[DIFF Date])) with DIFF Date as the difference
 
between today and the table date for each row.
Now I want to calculate the second newest value. For that I tried to work with ranking the DIFF Date values by a measure like the following:
 
Rank = RANKX(All(Gesamt[Datum]),CALCULATE(AVERAGE(Gesamt[DIFF Date])))
 
which give the right ranking if I show it in a table visual. 
My idea was to create another measure which includes a filter on "Rank=MAX-1". But as I know now, the filter in "Calculate" do only work with colums and not with measure (right?). 
Do you guys have any other idea to get that second latest value? I want to do calculations afterwards (Difference between newest and second latest) so a simple visual filter won't work unfotunately. 
 
Thank you in advance for your help, I really appreciate your time. 
Strueddi
4 REPLIES 4
mh2587
Super User
Super User

//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!




LinkedIn Icon
Muhammad Hasnain



Anonymous
Not applicable

Hi

if I try this, I got an error message (as in the picture). 

Strueddi_0-1708069384683.png

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 

mh2587
Super User
Super User

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!




LinkedIn Icon
Muhammad Hasnain



Anonymous
Not applicable

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?

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.