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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
TomEnns
Helper I
Helper I

DAX to Return list of duplicate customers

I have a table called CHA_Customer that looks something like this: 

CustIDName
12Apple
23Google
54Microsoft
59Microsoft
65Apple
78Apple

 

I want to add a measure called "DuplicateCustIDs" to the table to get the following output: 

CustIDNameDuplicateCustIDs
12Apple65,78
23Google 
54Microsoft59
59Microsoft54
65Apple12,78
78Apple12,65

 

Essentially, I want to search through the Name column on the customer table to determine which of the customer IDs have duplicate names and then make a list of those duplicates in a measure. I very much want to do this in DAX rather than M if it's possible. I have been playing with the "Earlier" function and can't see to get it to work even for a count of duplicate much less a list. Hoping someone here can help me out 

1 ACCEPTED SOLUTION

Hi @TomEnns 

 

Trying adding an ALLEXCEPT (Table, Table[Name] ) to your function:

Measure = 
VAR _custID = SELECTEDVALUE ( 'Table'[CustID] )
RETURN
CONCATENATEX ( 
    CALCULATETABLE ( 
        VALUES( 'Table' ),
        ALLEXCEPT ( 'Table', 'Table'[Name] ),
        'Table'[CustID] <> _custID
    ), 
    'Table'[CustID], ", "
)

 

result without the ALLEXCEPT:

tomfox_0-1664303259104.png

 

result with ALLEXCEPT:

tomfox_1-1664303283805.png

 

 

Does this solve your query? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

7 REPLIES 7
v-yueyunzh-msft
Community Support
Community Support

Hi , @TomEnns 

According to your description, you want to show the duplicate customers' ID in visual. Right?

Here are the steps you can refer to :

(1)This is my test data:

vyueyunzhmsft_0-1664335380281.png

(2)We ca  create a measure:

Measure = var _current_name = SELECTEDVALUE('Sheet2'[Name])
var _current_ID=SELECTEDVALUE('Sheet2'[CustID])
var _mul_t =SELECTCOLUMNS( FILTER( ALLSELECTED('Sheet2') , 'Sheet2'[Name]=_current_name && 'Sheet2'[CustID] <>_current_ID) ,"ID" , [CustID])
return
CONCATENATEX(_mul_t,[ID],",")

(3)Then we put the measure and the field you need in visual , and we will meet your need:

vyueyunzhmsft_1-1664335446546.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

TomEnns
Helper I
Helper I

@tackytechtom  That seems to do the trick with on caveat, for some reason this is now my output: 

TomEnns_0-1664304625093.png

 

As you can see EPIC06 shows three times for EPICF but there are not three matches. 

 

 

Hi @TomEnns ,

 

At this point, I think it's better if you provide a sample of your data. I have the feeling that there are other things that the formular needs to take into consideration due to the apparent data.

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @TomEnns ,

 

How about this:

tomfox_0-1664300691711.png

 

And here the code in DAX:

Measure = 
VAR _custID = SELECTEDVALUE ( 'Table'[CustID] )
RETURN
CONCATENATEX ( 
    CALCULATETABLE ( 
        VALUES ( 'Table'[CustID]), 
        'Table'[CustID] <> _custID
    ), 
    'Table'[CustID], ", "
)

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hey @tackytechtom Thankyou for the solution, it looks to do exactly what I want if those two columns are the only columns in my table. Of course I didnt post that I have additional columns in my table such as: 

 

Company

Address

City

Country

SalesPerson

TaxCode

and so on. 

 

When I add any of these columns to the table visualization it appears to break the measure and it doesnt display properly. As an exmaple this is with only the CustID, Name, and Measure: 

 

TomEnns_0-1664302614264.png

 

If I add company I get nothing: 

TomEnns_1-1664302659313.png

 

If I add address it filters out the data to only 2 rows: 

TomEnns_2-1664302715474.png

Any Idea on how to modify the measure to ensure it will always output the duplicates even if there are other rows in the query? 

 

 

Hi @TomEnns 

 

Trying adding an ALLEXCEPT (Table, Table[Name] ) to your function:

Measure = 
VAR _custID = SELECTEDVALUE ( 'Table'[CustID] )
RETURN
CONCATENATEX ( 
    CALCULATETABLE ( 
        VALUES( 'Table' ),
        ALLEXCEPT ( 'Table', 'Table'[Name] ),
        'Table'[CustID] <> _custID
    ), 
    'Table'[CustID], ", "
)

 

result without the ALLEXCEPT:

tomfox_0-1664303259104.png

 

result with ALLEXCEPT:

tomfox_1-1664303283805.png

 

 

Does this solve your query? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

I did some more digging into my dataset. It was my fault. This works exactly as needed. Thankyou!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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