Forum Discussion
Filtering table for rows showing the max date per group
- 3 years ago
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
- 3 years ago
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.
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
- TJohnson67543 years agoFrequent Visitor
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!
- milanpasschier33 years ago
Resolver I
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.
- TJohnson67543 years agoFrequent Visitor
This is perfect, thank you so much!!