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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
TJohnson6754
Frequent Visitor

Filtering table for rows showing the max date per group

Hi all,

 

I have a table that is arranged somewhat like this:

RowIDConsumerIDVisitDate
111114/1/2023
222224/1/2023
311113/9/2023
433335/1/2023
522223/8/2023
633333/9/2023
711113/8/2023
811112/14/2023
933331/28/2023
1022223/31/2023

 

I'm trying to filter for the most recent VisitDate for each ConsumerID so that there will be 1 row per ConsumerID:

RowIDConsumerIDVisitDate
111114/1/2023
222224/1/2023
433335/1/2023

 

I feel like I've done this before (successfully) but everything I've tried this time has yielded either errors or unfiltered data. 

I've tried using combinations of Filter, groupby, max, maxx, summarize, summarizecolumns, topn, etc. I'm sure this is much simpler than I'm making it. Can someone point me in the right direction?

2 ACCEPTED SOLUTIONS
milanpasschier3
Resolver I
Resolver I

Ok, you should create a new table (in my case Sheet1_filtered) with a column named consumerID (same name as your current table). You can get the distinct ids via:

 

 

Sheet1_filtered = DISTINCT(Sheet1[ConsumerID])

 

 

You can than calculate the most recent VisitDate for each ConsumerID in a new column.

 

 

MostRecentVisitDate = CALCULATE (
    MAX (Sheet1[VisitDate]),
    FILTER ( Sheet1, Sheet1[ConsumerID] = EARLIER ( Sheet1_filtered[ConsumerID] ) )
)

 

 

Make sure there is a relationship between the two consumerID in both tables (use the model view).

 

Sheet1 is your current table. Sheet1_filtered will the table that you should create.

 

Let me know if this works.

 

Best,

 

Milan

View solution in original post

Cool cool, try in the filtered table:

 

 

RelatedRowID = 

VAR ConsumerID = Sheet1_filtered[ConsumerID]
VAR MostRecentVisitDate = Sheet1_filtered[MostRecentVisitDate]

RETURN

CALCULATE (
    MAX( Sheet1[RowID]),
    Sheet1[ConsumerID] == ConsumerID &&
    Sheet1[VisitDate] == MostRecentVisitDate
)

 

Best,

 

Milan

 

PS. Make sure to thumbs up and mark as solution if it fits your needs.

 

View solution in original post

6 REPLIES 6
milanpasschier3
Resolver I
Resolver I

Ok, you should create a new table (in my case Sheet1_filtered) with a column named consumerID (same name as your current table). You can get the distinct ids via:

 

 

Sheet1_filtered = DISTINCT(Sheet1[ConsumerID])

 

 

You can than calculate the most recent VisitDate for each ConsumerID in a new column.

 

 

MostRecentVisitDate = CALCULATE (
    MAX (Sheet1[VisitDate]),
    FILTER ( Sheet1, Sheet1[ConsumerID] = EARLIER ( Sheet1_filtered[ConsumerID] ) )
)

 

 

Make sure there is a relationship between the two consumerID in both tables (use the model view).

 

Sheet1 is your current table. Sheet1_filtered will the table that you should create.

 

Let me know if this works.

 

Best,

 

Milan

Thank you, this is great! Is there a way to also retain the other column(s)? In my example data, it would be RowID column. I tried using LookupValue but since the most recent visit date isn't a unique value, it doesn't work to find its corresponding RowID value. Perhaps I concatenate the ConsumerID and MostRecentVisitID column values in both tables? Is there another way to do it? Thank you so much!

Cool cool, try in the filtered table:

 

 

RelatedRowID = 

VAR ConsumerID = Sheet1_filtered[ConsumerID]
VAR MostRecentVisitDate = Sheet1_filtered[MostRecentVisitDate]

RETURN

CALCULATE (
    MAX( Sheet1[RowID]),
    Sheet1[ConsumerID] == ConsumerID &&
    Sheet1[VisitDate] == MostRecentVisitDate
)

 

Best,

 

Milan

 

PS. Make sure to thumbs up and mark as solution if it fits your needs.

 

This is perfect, thank you so much!!

milanpasschier3
Resolver I
Resolver I

Hey, just to be sure... Do you want this as a measure or do you want a new table with the filtered data? Best, Milan

 

Hi there,

Ideally, I'm looking for a filtered table that retains all the columns. Thank you for taking a look at this!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.