Forum Discussion

JMHenriques's avatar
JMHenriques
Frequent Visitor
4 years ago
Solved

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:

 

UniqueIDSomeother_IDWeekYearParentorChild
1ABC-123-XDR51-21Parent
2DRF-546-CFR51-21Parent
3BGT-433-FTT51-21Parent
4ABC-123-XDR51-21Child
5ABC-123-XDR52-21Parent
6DRF-546-CFR52-21Parent
7BGT-433-FTT52-21Parent
8ABC-123-XDR52-21Child
9ABC-123-XDR1-22Parent
10DRF-546-CFR1-22Parent
11BGT-433-FTT1-22Parent
12ABC-123-XDR1-22Child
13ABC-123-XDR1-22Child

 

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

  • 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/