Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JMHenriques
Frequent Visitor

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

1 ACCEPTED SOLUTION
VahidDM
Super User
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:

VahidDM_0-1641515512824.png

 

 

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/

 

 

View solution in original post

1 REPLY 1
VahidDM
Super User
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:

VahidDM_0-1641515512824.png

 

 

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/

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.