Forum Discussion
How to find second latest date after max date
Hi all,
I am trying to find the second latest date after the MAX date.
orderdate
2019-12-11
2019-12-31
2019-12-31
This is what I have tried but doesn't seem to work.
``` calculate(max(orders[orderdate]),
filter(orders, orders[orderdate]<> max(orders[orderdate])))```
Any idea on how I can return 2019-12-11?
TIA
16 Replies
- v-frfei-msft
Community Support
Hi Dee ,
Please create a measure as below.
Measure = VAR maxdate = CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) ) RETURN CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( ALL ( 'Table' ), 'Table'[Date] < maxdate ) )For more details, please check the pbix as attached.
- Dee
Helper III
I tried all the mentioned solutions but I still get the same date different from the real second date.
- AnonymousNot applicable
Dee - Is the column a Date/Time column? If so, this could be problematic. You can convert it to a date column in Power Query.
- Dee
Helper III
Anonymous you mean this pbix file?
- AnonymousNot applicable
Dee - You can do a measure like the following:
Second Largest = var _Largest = max(Orders[orderdate]) return CALCULATE( max(Orders[orderdate]), Orders[orderdate] < _Largest ) - amitchandak
Super User
try putting all
calculate(max(orders[orderdate]), filter(all(orders), orders[orderdate]<> max(orders[orderdate]))) or calculate(max(orders[orderdate]),all(orders[orderdate]), filter(orders, orders[orderdate]<> max(orders[orderdate])))- harshadrokade
Post Partisan
Hi amitchandak
How to get last to last year from the database. Like if I have below data in the table, I want year 2018 & not 2019.
20212020
2018
- AnonymousNot applicable
Have this been solved?
Am I right in thinking that you are looking for the previous date to the max date?
I had a similar issue and someone gave me the following formula. This will look for the previous date before your MAX date. If there is no date then the MAX date will be given.
Previous =
VAR MaxDate = CALCULATE(MAX('Table1'[Date]), ALL('Table1'[Date]))
VAR PreviousDate = CALCULATE(MAX('Table1'[Date]), 'Table1'[Date] < MaxDate)
return IF(ISBLANK(PreviousDate), MaxDate, PreviousDate)
- eric98
Helper II
It's a measure or a column ?
- Dilushi_DB24New Member
Do you know how to get the days difference between the last date and the second last date of a specific customer? Please can anyone assist?