Forum Discussion
Filtering for most recent date in a group
Hello,
I'm trying to only show the line that has the most recent RoleLastUpdate (see Image) for each distinct RoleID..
I've tried this solution, however this only shows the most recent date for the whole table.
Solved: Filtering table for rows showing the max date per ... - Microsoft Fabric Community
This solution is supposed to put a '1' next to the latest date, which can then be filtered on, however it's putting a one next to every date (image - last column). I've checked the example from the solution and mine looks the same, aside from the table/column names.
Solved: How to Filter a Table To Show Only Most Recent Dat... - Microsoft Fabric Community
The only filter I have on is for specific users, which shouldn't effect results as they're grouped by RoleID, and in this case the same user is attached to each.
DAX used.
Can anyone see where it's going wrong?
Thanks.
8 Replies
- lbendlin
Super User
Instead of ALLSELECTED use REMOVEFILTERS on the date column.
- AnonymousNot applicable
Hi PartyFish88 ,
As lbendlin said, using the REMOVEFILTERS function is a viable approach. Below is my answer.
It seems you’re on the right track with your DAX formula, but there’s a small adjustment needed to achieve the desired result.
Here’s the revised DAX measure:
MostRecentUpdateFilter2.0 = VAR maxdate = CALCULATE( MAX('Legal IR35RoleReview'[RoleLastUpdate]), ALLSELECTED('Legal IR35RoleReview') ) RETURN IF( 'Legal IR35RoleReview'[RoleLastUpdate] = maxdate, 1, BLANK() )By doing so, we’re now comparing the date for each row against the maximum date across all rows, regardless of the specific RoleID. This should correctly mark only the most recent date with a ‘1’ in your result.
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- PartyFish88Regular Visitor
Anonymous lbendlin
I've tried both of your solutions, unfortunately they only bring back the most recent RoleUpdate (last night).I need to bring in the most recent Role update for each unique RoleID 🤔
- lbendlin
Super User
In your version 4.0 what's the purpose of the VALUES filter?
- talespin
Solution Sage
hi PartyFish88
Can you please try this measure, I just typed it in notepad, please check syntax.
Measure =
VAR _RoleLastUpdate = SELECTEDVALUE('Legal IR35RoleReview'[RoleLastUpdate])
VAR _RoleID = SELECTEDVALUE('Legal IR35RoleReview'[RoleID])
VAR maxdate =
CALCULATE(
MAX ('Legal IR35RoleReview'[RoleLastUpdate]),
REMOVEFILTERS('Legal IR35RoleReview'),
'Legal IR35RoleReview'[RoleID] = _RoleID
)RETURN IF( _RoleLastUpdate = maxdate, 1, BLANK() )
- PartyFish88Regular Visitor
Hi talespin
Thank you for your solution, unfortunately it's putting a '1' next to each entry rather than those with the most recent dates (see image).- talespin
Solution Sage
hi PartyFish88
In the visual, are all attributes from same table?
If possible please share pbix file with all sensitive data removed(or with mockup data).