Forum Discussion
Value associated with second most recent date
- 6 years ago
I just tried the measure on your test data and it works as expected. What error are you getting exactly?
2nd Recent Value = var thisdate= max('DATA SHEET ACTUALS'[Date]) var seconddate = CALCULATE(max('DATA SHEET ACTUALS'[Date]),'DATA SHEET ACTUALS'[Date]<thisdate) return CALCULATE(SUM('DATA SHEET ACTUALS'[Value]),'DATA SHEET ACTUALS'[Date] = seconddate)
try this one. Might need some fine tuning.
2nd Recent Value =
var thisdate= max('DATA SHEET ACTUALS'[Date])
var seconddate = CALCULATE(max('DATA SHEET ACTUALS'[Date]),'DATA SHEET ACTUALS'[Date]<thisdate)
return CALCULATE(SUM('DATA SHEET ACTUALS'[Value]), FILTER(ALL('DATA SHEET ACTUALS'), 'DATA SHEET ACTUALS'[Date] = seconddate))
- nthomson6 years agoFrequent Visitor
Thanks for the help, however I think this leads to similar problem, i.e with the 'seconddate' formula you've suggested, it seems you're not allowed to use a measure within the formula to derive a value, so the '<[thisdate]' portion throws an error.
I've built the measure for the seconddate already, it's just deriving the actual value from it that I'm struggling with.
- lbendlin6 years ago
Super User
I just tried the measure on your test data and it works as expected. What error are you getting exactly?
2nd Recent Value = var thisdate= max('DATA SHEET ACTUALS'[Date]) var seconddate = CALCULATE(max('DATA SHEET ACTUALS'[Date]),'DATA SHEET ACTUALS'[Date]<thisdate) return CALCULATE(SUM('DATA SHEET ACTUALS'[Value]),'DATA SHEET ACTUALS'[Date] = seconddate)- nthomson6 years agoFrequent Visitor
Apologies, user error when entering - working now. Many thanks for your help!