Forum Discussion
MAXX Returning duplicate values
- 3 months ago
The duplicate happens because both rows share the same JobNumber AND the same JobDate, so the IF test passes for both. You need a tiebreaker so only one row wins.
If your table has any unique row identifier (an Index column added in Power Query works well), use it as a secondary key:
MaxDateFlag =
VAR MaxDateForJob = MAXX ( FILTER ( 'Jobs', 'Jobs'[JobNumber] = EARLIER ( 'Jobs'[JobNumber] ) ), 'Jobs'[JobDate] )
VAR MaxIndexForJob = MAXX ( FILTER ( 'Jobs', 'Jobs'[JobNumber] = EARLIER ( 'Jobs'[JobNumber] ) AND 'Jobs'[JobDate] = MaxDateForJob ), 'Jobs'[Index] )
RETURN IF ( 'Jobs'[Index] = MaxIndexForJob, 'Jobs'[JobDate], BLANK () )If you do not already have an Index column, add one in Power Query (Add Column then Index Column from 0). The first MAXX gets the latest date per JobNumber, the second picks the row with the largest Index among the tied dates, and the IF flags only that one.
If this helped, a thumbs up and accepting the solution would be appreciated.
Best,
Shai Karmani
The duplicate happens because both rows share the same JobNumber AND the same JobDate, so the IF test passes for both. You need a tiebreaker so only one row wins.
If your table has any unique row identifier (an Index column added in Power Query works well), use it as a secondary key:
MaxDateFlag =
VAR MaxDateForJob = MAXX ( FILTER ( 'Jobs', 'Jobs'[JobNumber] = EARLIER ( 'Jobs'[JobNumber] ) ), 'Jobs'[JobDate] )
VAR MaxIndexForJob = MAXX ( FILTER ( 'Jobs', 'Jobs'[JobNumber] = EARLIER ( 'Jobs'[JobNumber] ) AND 'Jobs'[JobDate] = MaxDateForJob ), 'Jobs'[Index] )
RETURN IF ( 'Jobs'[Index] = MaxIndexForJob, 'Jobs'[JobDate], BLANK () )
If you do not already have an Index column, add one in Power Query (Add Column then Index Column from 0). The first MAXX gets the latest date per JobNumber, the second picks the row with the largest Index among the tied dates, and the IF flags only that one.
If this helped, a thumbs up and accepting the solution would be appreciated.
Best,
Shai Karmani