Max date for User ID - Multiples dates in a Table

zapppsr

Board Regular
Joined
Aug 19, 2010
Messages
189
This one should be simple and I'm not getting it right:

md.png


I want to create a Calculated Column that shows the Max date for the ID.

ID 1 has 01/01/2010, 01/01/2011 and 01/01/2012. The Max Date for this ID is 01/01/2012.

Hou can I create a DAX formula to create that Column?

Thanks in advance.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
In the 3rd column, you can enter:

=MAX([Date])

Try first to add A1:B10 to the data model (Add to the Data Model).
 
Upvote 0
Hi, thanks for replying.

It does not seem to work. It gets the Max Date of ALL.. not for ID.

md1.png
 
Upvote 0
Try
Code:
MaxDate =
CALCULATE
    MAX ( fAntrop[Data] ),
    ALLEXCEPT ( fAntrop, fAntrop[ID] )
)
 
Upvote 0
Ok, that's perfect, thank you! But, now explain me what happened:

ALLEXCEPT removes all the filters from the table, except for the column specified in its arguments.
Did it use calculate to filter the whole table, except the ID of the current row?

Thanks again!

m2.png
 
Upvote 0
No problem :)

First of all, CALCULATE (used in a calculated column) turns the current row context into a filter context including all values in the current row (context transition).
But since we only want to use the ID from the current row (rather than all columns), ALLEXCEPT is used to clear all filters except for ID.
ALLEXCEPT ( fAntrop; fAntrop[ID] ) tells CALCULATE to clear all filters except for fAntrop[ID].

The end result is that we have created a filter context containing just a filter on fAntrop[ID] corresponding to the value in the current row.

We can then calculate MAX ( fAntrop[Data] ) in that context to get the maximum date across all rows corresponding to the current row's ID.
 
Upvote 0
Hi, thanks again for replying.

Maybe the name of the function is misleading. Before seeing your solution, I thought ALLEXCEPT worked like this:

ALL = ID 1, 2 and 3.
ALLEXCEPT ID 1 = ID 2 and 3 - On other words ALL IDs, except the one I'm telling you.

But it does the exact opposite:

ALLEXCEPT ID1 = ID 1

It is kinda confusing isn't it? - How do you reason to understand the behaviour and the name.
 
Upvote 0
Yes, I agree the naming of ALL and ALLEXCEPT can be confusing, especially when they are used as top level arguments within CALCULATE.

To quote The Definitive Guide to DAX, "You should read ALL as REMOVEFILTERS".
And I would add you should read ALLEXCEPT as REMOVEFILTERS EXCEPT.

In your example, ALLEXCEPT is removing all filters except ID, so just the current ID remains in the filter context.

By the way, the behaviour you described is something you can do with the EXCEPT function. For example EXCEPT ( ALL ( fAntrop[ID] ), VALUES ( fAntop[ID] ) ), would invert the values of ID currently visible in the filter context.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,739
Messages
6,132,441
Members
449,728
Latest member
teodora bocarski

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