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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jij19
Helper I
Helper I

Delete duplicates after columns are calculated in DAX

I have a table with IDs in a column which have Sub IDs in another column and each row can have a different service entered date. In the same table there are a lot of other columns and also some calculated columns which also should be displayed in the output, but these columns don't change. They just also belong to the rows.

Example:

 

 

ID     Sub ID            Entered date

1010001 02/05/2022
1010002 02/10/2022
1010003 02/12/2022
2020001 03/02/2022
2020002 02/20/2022

 

I want to get this output by deleting duplicated id's and only take the first entered row:

 

ID      Sub ID           Entered date

1010001 02/05/2022
2020002 02/20/2022

 

14 REPLIES 14
PaulDBrown
Community Champion
Community Champion

Here is one way of creating a measure to filter the rows in the table:

Filter Measure =
COUNTROWS (
    SUMMARIZE (
        FILTER (
            'Table',
            'Table'[EnteredDate]
                = CALCULATE ( MIN ( 'Table'[EnteredDate] ), ALLEXCEPT ( 'Table', 'Table'[ID] ) )
        ),
        'Table'[ID],
        'Table'[Sub ID],
        'Table'[EnteredDate]
    )
)

Add the measure to the filters for the visual in the filter pane and set the value to 1:

result.jpg

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Doesn't work for me with this code. I still get duplicates with that

ryan_mayu
Super User
Super User

@jij19 

pls try this

sub id = maxx(FILTER('Table','Table'[ID]=max('Table'[ID])&&'Table'[Date]=min('Table'[Date])),'Table'[SubID])

enterdate = min('Table'[Date])

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Yes the output is good but I would like to have it as a new table output and npt in the dashboard view, sorry didn't mentioned that

 

So it would be some DAX code.

 

Do you know how to do that?

you can try this

Table 2 = 
var tbl=SUMMARIZE('Table','Table'[ID],"date2",min('Table'[Date]))
return ADDCOLUMNS(tbl,"SUBID",maxx(FILTER('Table','Table'[ID]=EARLIER('Table'[ID])&&'Table'[Date]=[date2]),'Table'[SubID]))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




this one is good, but is there any way how I can get all the other columns from the old dataset to this new table. the rest of the columns should also be displayed. A way to extend the code and add the rest of the columns without any rule?

@jij19 

You can try this

Table 2 = 
VAR TBL=ADDCOLUMNS('Table',"CHECK",IF('Table'[ENTERDATE]=CALCULATE(MIN('Table'[ENTERDATE]),ALLEXCEPT('Table','Table'[ID])),1))
return FILTER(TBL,[CHECK]=1)

1.PNG

or

Table 2 = 
VAR TBL=ADDCOLUMNS('Table',"CHECK",IF('Table'[ENTERDATE]=CALCULATE(MIN('Table'[ENTERDATE]),ALLEXCEPT('Table','Table'[ID])),1))
VAR TBL2=FILTER(TBL,[CHECK]=1)
RETURN SELECTCOLUMNS(TBL2,"ID",'Table'[ID],"SUBID",'Table'[SUBID],"ENTERDATE",'Table'[ENTERDATE])

2.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




The first one with check would be good but I still get duplicated rows. So the duplicates are still in the output. 

 

In the second code it doesn't show any added "check" column in the output.

 

Thanks in advance

Example:

 

 

ID     Sub ID            Entered date          Team

1010001 02/05/2022 A
1010002 02/10/2022 A
1010003 02/12/2022 B
2020001 03/02/2022 C
2020002 02/20/2022 C

 

I want to get this output by deleting duplicated id's and only take the first entered row:

 

ID      Sub ID           Entered date         Team

1010001 02/05/2022 A
2020002 02/20/2022 C

 

 

Maybe this helps. So the table contains a lot more columns which also should be displayed in the output. 

@jij19 

pls try this

Table 2 = 
VAR TBL=ADDCOLUMNS('Table',"CHECK",IF('Table'[ENTERed DATE]=CALCULATE(MIN('Table'[ENTERed DATE]),ALLEXCEPT('Table','Table'[ID])),1))
VAR TBL2=FILTER(TBL,[CHECK]=1)
RETURN SELECTCOLUMNS(TBL2,"ID",'Table'[ID],"SUBID",'Table'[SUBID],"ENTERDATE",'Table'[ENTERed DATE],"team",'Table'[Team])

1.PNG

if you have more columns, just add them in the selectcolumn function.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




That looks almost good! unfortunately I still get duplicates with this code

 

@jij19 

maybe you need to provide more sample data. 

or  try this

Table 2 = 
VAR TBL=ADDCOLUMNS('Table',"CHECK",IF('Table'[ENTERed DATE]=CALCULATE(MIN('Table'[ENTERed DATE]),ALLEXCEPT('Table','Table'[ID])),1))
VAR TBL2=FILTER(TBL,[CHECK]=1)
VAR TBL3= SELECTCOLUMNS(TBL2,"ID",'Table'[ID],"SUBID",'Table'[SUB ID],"ENTERDATE",'Table'[ENTERed DATE],"team",'Table'[Team])
RETURN SUMMARIZE(TBL3,[ID],[SUBID],[ENTERDATE],[team])

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I think it is the right solution. I still get duplicates but this is because I have IDs with multiple rows (Sub ID) with the same entered date. So it takes all rows with the min entered date if there are more than one with the same one. 

Is there a way tho include the Sub ID as well. I mean that the code looks for the min entered date and also the min Sub ID number?

 

Thank you @ryan_mayu 

@jij19 

In order to provide the better solution, could you pls provide the sample data?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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