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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Second Last and Third Last values not showing all values

Hello,

I would like to build some measures that will show the Second Last and Third last values, so I can use them lately in a formula. I have two years of dat, 2013, 2014 with 4 readings in 2013 and 3 readings in 2014. I created the measures for first value and last value and they work fine. But when I calculated second last and thirdlast values when visualize, it doesn't show all values. Here is the table with all data

Cristian1_0-1668447582049.png

Cristian1_2-1668447679952.png

 

and the table when using the measures, with a slicer for year. As you can see is that for 2013, second and third last values doesn't show all values. Not sure why. Any help is much appreciated. Thank you.

Here are the measures I used. I would like to insert the .pbix file, but not sure how.

FirstValue =
    CALCULATE ( MIN ( 'Piping UT ex'[Value]), FIRSTDATE ( 'Piping UT ex'[Date] ) )
LastValue =
CALCULATE(MIN('Piping UT ex'[Value]), LASTDATE('Piping UT ex'[Date]))
LatestDate =
    MAX('Piping UT ex'[Date])
SecondLatestDate =
VAR __LatestDate = [LatestDate]
RETURN
CALCULATE (
MAX ( 'Piping UT ex'[Date] ),
KEEPFILTERS ( 'Piping UT ex'[Date] < __LatestDate )
)
SecondLatestValue =
VAR __SecondLatestDate = [SecondLatestDate]
RETURN
CALCULATE (
SELECTEDVALUE ( 'Piping UT ex'[Value] ),
KEEPFILTERS ( 'Piping UT ex'[Date] = __SecondLatestDate )
)
ThirdLatestDate =
VAR __SecondLatestDate = [SecondLatestDate]
RETURN
CALCULATE (
MAX ( 'Piping UT ex'[Date] ),
KEEPFILTERS ( 'Piping UT ex'[Date] < __SecondLatestDate )
)
ThirdLatestValue =
VAR __ThirdLatestDate = [ThirdLatestDate]
RETURN
CALCULATE (
SELECTEDVALUE ( 'Piping UT ex'[Value] ),
KEEPFILTERS ( 'Piping UT ex'[Date] = __ThirdLatestDate )
)

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @v-easonf-msft ,thank you for looking into it. I figured that was the case so I digged into the dataset example and I found multiple values for same dates, I cleaned it and it works. Lesson learned. Much appreciate your reply. Thank you

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

No obvious problems were found in the formula. I may need more details.

You can upload your sample file to cloud storage and share the public link here.

 

Best Regards,
Community Support Team _ Eason

Anonymous
Not applicable

Hi @v-easonf-msft ,thank you for looking into it. I figured that was the case so I digged into the dataset example and I found multiple values for same dates, I cleaned it and it works. Lesson learned. Much appreciate your reply. Thank you

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors