Forum Discussion
Max Date Per Category
Hi all,
I have a table such as the below:
| Color | Name | Date |
| Purple | Joe | 1/1/2023 |
| Green | Larry | 1/1/2023 |
| Red | Moe | 1/1/2023 |
| Purple | Curly | 5/1/2023 |
| Purple | Joe | 5/1/2023 |
| Red | Shemp | 1/1/2023 |
I am trying to remove duplicates, of Color category, removing earlier dates. Essentially, remove all records that are not equal to the max date per each of the color categories. The output would look like the below. Note that the first record of "purple" is removed as max is 5/1, and all instances of "red" are kept as they equal the max date.
| Color | Name | Date |
| Green | Larry | 1/1/2023 |
| Red | Moe | 1/1/2023 |
| Purple | Curly | 5/1/2023 |
| Purple | Joe | 5/1/2023 |
| Red | Shemp | 1/1/2023 |
Thanks,
Use this code in calculated table,
Max Date = VAR _tempTable = SUMMARIZE( 'Table', 'Table'[Color], 'Table'[Name], "@Date",MAX('Table'[Date])) RETURN _tempTableThanks,
Arul
6 Replies
- Arul
Super User
Can you try this measure?
Max Date = VAR _tempTable = SUMMARIZE( 'Table', 'Table'[Color], "@Date",MAX('Table'[Date])) VAR _result = CALCULATE( MAXX(_tempTable,[@Date]), 'Table'[Date] = MAXX(_tempTable,[@Date])) RETURN _resultThanks,
Arul
- shuhn1229
Resolver I
dear Arul ,
Sorry for not clarifying, i'd need this data to be a new table so that I can join it to the model.
When creating a new table using that expression I get the following error: The expression specified in the query is not a valid table expression.
Max Date =
VAR _tempTable =
SUMMARIZE(
'Table',
'Table'[Color],
"@Date",MAX('Table'[Date]))
VAR _result =
CALCULATE(
MAXX(_tempTable,[@Date]),
'Table'[Date] = MAXX(_tempTable,[@Date]))
RETURN _resultI am replacing the bolded above with my data. Hopefully I am understanding your formula above?
Steve