Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PartyFish88
Regular Visitor

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..

PartyFish88_0-1708704317152.png

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.

MostRecentUpdateFilter2.0 =
VAR maxdate =
    CALCULATE(
        MAX ('Legal IR35RoleReview'[RoleLastUpdate]),
        ALLSELECTED ('Legal IR35RoleReview'),
        VALUES ('Legal IR35RoleReview'[RoleID])  
    )
RETURN
    IF(MAX('Legal IR35RoleReview'[RoleLastUpdate]) = maxdate, 1, BLANK() )

Can anyone see where it's going wrong?

Thanks.
8 REPLIES 8
talespin
Solution Sage
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() )

 

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).

PartyFish88_0-1709031046159.png

 

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).

v-yilong-msft
Community Support
Community Support

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.

@v-yilong-msft @lbendlin 
I've tried both of your solutions, unfortunately they only bring back the most recent RoleUpdate (last night).

PowerBI Filter DAX Try 1.png

PartyFish88_0-1708946228477.png

I need to bring in the most recent Role update for each unique RoleID 🤔

In your version 4.0 what's the purpose of the VALUES filter?

The VALUES filter is supposed to group events/updates together by their RoleID, this being a unique identifier. The rest of the DAX is supposed to put a '1' next to the most recent RoleLastUpdate which can then be filtered on, showing only the most recent RoleUpdate for each RoleID 🙂

I say supposed to, DAX isn't really my fortay . . . yet 😅

lbendlin
Super User
Super User

Instead of ALLSELECTED use REMOVEFILTERS on the date column.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors