Calculate most recent date

Daxquest

New Member
Joined
Nov 4, 2015
Messages
2
Hi,

I have a table of document changes. Each row contains a document id and a time when the change occurred. I need to report on this data in two modes: one that reports on all changes, and another that reports on only the most recent changes for a given document. In order to do this, I think I need a calculated field that shows whether the given row represents the most recent change. As an example, here's what I have:

change_datedocument_id
5/1/2015a
5/1/2015b
5/1/2015c
5/1/2015d
6/20/2015a
6/20/2015b
6/20/2015c
6/20/2015e
6/20/2015f
7/11/2015a
7/11/2015b
7/11/2015f
7/11/2015g

<tbody>
</tbody>

I think what I want is a calculated column that has a 1 if the row is the most recent change, and a 0 if not - then that column can be used as a filter and also to sum and in various other calculations.

My problem is that I can't figure out how to calculate this. My first thought was something like:

Code:
=if(
    lastdate( filter( Table, Table[document_id] = [document_id] ) ) = [change_date],
    1, 0
)

But lastdate() wants just a column, not the entire table that filter() spits out. Same with max(). I can't figure out how to narrow down the return of filter() to a single column for the benefit of lastdate(), and I can't figure out an alternative to lastdate() (or max(), which also expects a column) to use instead. Am I missing something? Should I take a different approach?

Many thanks!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Here are two ways I can think of. MAX can also be replaced with LASTDATE in this case.
Code:
=IF (
     Table[change_date]
        = CALCULATE (
            MAX ( Table[change_date] ),
            ALLEXCEPT ( Table, Table[document_id] )
        ),
    1,
    0
)
Code:
=
IF (
    Table[change_date]
        = CALCULATE (
            MAX ( Table[change_date] ),
            FILTER ( Table, Table[document_id] = EARLIER ( Table[document_id] ) )
        ),
    1,
    0
)
 
Upvote 0

Forum statistics

Threads
1,214,390
Messages
6,119,235
Members
448,879
Latest member
VanGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top