Forum Discussion
Calculated column to identify duplicates with filters
Hi everyone,
I need to create a calculated column (named ParentorChild in the example below) that identify me, for each week, the first duplicated ID as "Parent" and the remaining ones as "child". The Parent should always be the one with the lower UniqueID. Example in the table below:
| UniqueID | Someother_ID | WeekYear | ParentorChild |
| 1 | ABC-123-XDR | 51-21 | Parent |
| 2 | DRF-546-CFR | 51-21 | Parent |
| 3 | BGT-433-FTT | 51-21 | Parent |
| 4 | ABC-123-XDR | 51-21 | Child |
| 5 | ABC-123-XDR | 52-21 | Parent |
| 6 | DRF-546-CFR | 52-21 | Parent |
| 7 | BGT-433-FTT | 52-21 | Parent |
| 8 | ABC-123-XDR | 52-21 | Child |
| 9 | ABC-123-XDR | 1-22 | Parent |
| 10 | DRF-546-CFR | 1-22 | Parent |
| 11 | BGT-433-FTT | 1-22 | Parent |
| 12 | ABC-123-XDR | 1-22 | Child |
| 13 | ABC-123-XDR | 1-22 | Child |
What is the best way to accomplish this?
Many thanks in advance for your time and support,
Joao Henriques
Hi JMHenriques
Try this code to add a calculated column:
ParentorChild = VAR _A = CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( 'Table', 'Table'[UniqueID] <= EARLIER ( 'Table'[UniqueID] ) && 'Table'[WeekYear] = EARLIER ( 'Table'[WeekYear] ) && 'Table'[Someother_ID] = EARLIER ( 'Table'[Someother_ID] ) ) ) RETURN IF ( _A = 1, "Parent", "Child" )output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
1 Reply
- VahidDM
Super User
Hi JMHenriques
Try this code to add a calculated column:
ParentorChild = VAR _A = CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( 'Table', 'Table'[UniqueID] <= EARLIER ( 'Table'[UniqueID] ) && 'Table'[WeekYear] = EARLIER ( 'Table'[WeekYear] ) && 'Table'[Someother_ID] = EARLIER ( 'Table'[Someother_ID] ) ) ) RETURN IF ( _A = 1, "Parent", "Child" )output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/