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 latest date with data

Hi, 

 

I have a measure that shows data from the latest possible day and it works as expected. Somehow I fail building a measure for the second latest date because it is always showing data for the next day after latest and new data is not coming in daily. The timestamp value has a relation with the Date table.

 

Measure for latest works as expected:

Measure 1 =

var _latestday = CALCULATE(MAX('Date'[Date]))

RETURN
CALCULATE(SUM('Table'[count]), 'Table'[timestamp] = _latestday)

 

Measure for second latest works is returning second latest date even if count is blank.

Measure 2 =
var _secondlatestday = CALCULATE(MAX('Date'[Date]))-1

RETURN
CALCULATE(SUM('Table'[count]), 'Table'[timestamp] = _secondlatestday)

 

So today Measure 1 is returning 100 and Measure 2 blank when 140 is expeted. On Friday 8th of October Measure 1 was returning 140 and Measure 2 was returning 80. On Friday I thought my measure was working fine but today I realized something needs to be fixed.

 

timestampcount
10/10/21100
8/10/21140
7/10/2180
5/10/219
3/10/21-2

 

Thanks for your help in advance!

 

Julia

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @Anonymous 

 

try this:

VAR _2nd =
    CALCULATE (
        MAX ( 'Table'[timestamp] ),
        FILTER ( ALL ( 'Table' ), 'Table'[timestamp] < MAX ( 'Table'[timestamp] ) )
    )
RETURN
    CALCULATE ( SUM ( 'Table'[count] ), 'Table'[timestamp] = _2nd )

output:

VahidDM_0-1633956274012.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!


 
 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks a lot @VahidDM ! Your solution worked for my problem.

VahidDM
Super User
Super User

Hi @Anonymous 

 

try this:

VAR _2nd =
    CALCULATE (
        MAX ( 'Table'[timestamp] ),
        FILTER ( ALL ( 'Table' ), 'Table'[timestamp] < MAX ( 'Table'[timestamp] ) )
    )
RETURN
    CALCULATE ( SUM ( 'Table'[count] ), 'Table'[timestamp] = _2nd )

output:

VahidDM_0-1633956274012.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!


 
 

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.