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
__zhe
Frequent Visitor

Mark Differences Between 2 Table

Hi There,

I have 2 tables, Table 1 and Table 2 and i am trying to mark items that unique/not in each other table

 

 Capture.PNG

 

We can find and list with EXCEPT but how I want to just to mark it down ?

1 ACCEPTED SOLUTION

@__zhe

 

In that case, you can select the relevant columns first from both tables using "SELECTCOLUMNS" function

Then apply the above procedure

 

i.e.

 

Calculated Table =
VAR firstTable =
    SELECTCOLUMNS ( Table1, "ID", [ID], "Serial", [Serial], "Name", [Name] )
VAR SecondTable =
    SELECTCOLUMNS ( Table2, "ID", [ID], "Serial", [Serial], "Name", [Name] )
VAR Common =
    INTERSECT ( firstTable, SecondTable )
VAR NotCommon =
    EXCEPT ( DISTINCT ( UNION ( firstTable, SecondTable ) ), Common )
RETURN
    UNION (
        ADDCOLUMNS ( Common, "Unique", "No" ),
        ADDCOLUMNS ( NotCommon, "Unique", "Yes" )
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

12 REPLIES 12
Zubair_Muhammad
Community Champion
Community Champion

@__zhe

 

In above example, Shouldn't John be unqiue..since serial doesn't exist in Table 2?

 


Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad , السلام عليكم

Yes you're right, John should be unique and marked as "Yes" too 

@__zhe

 

Wa alaikumus salam

 

You can use this calculated table
From the Modelling Tab>>New Table

 

Calculated Table =
VAR Common =
    INTERSECT ( Table1, Table2 )
VAR NotCommon =
    EXCEPT ( DISTINCT ( UNION ( Table1, Table2 ) ), Common )
RETURN
    UNION (
        ADDCOLUMNS ( Common, "Unique", "No" ),
        ADDCOLUMNS ( NotCommon, "Unique", "Yes" )
    )

 

 


Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad I forgotten to mention those table have different structure and number of column . Wondering if Intersect can be based on certain column only, with name conversion 

 

e.g. INTERSECT(TABLE1,"Serial Number",[Serial Number]),INTERSECT(TABLE2,"Serial Number",[serialNum1XXX)) ... ... ?

@__zhe

 

In that case, you can select the relevant columns first from both tables using "SELECTCOLUMNS" function

Then apply the above procedure

 

i.e.

 

Calculated Table =
VAR firstTable =
    SELECTCOLUMNS ( Table1, "ID", [ID], "Serial", [Serial], "Name", [Name] )
VAR SecondTable =
    SELECTCOLUMNS ( Table2, "ID", [ID], "Serial", [Serial], "Name", [Name] )
VAR Common =
    INTERSECT ( firstTable, SecondTable )
VAR NotCommon =
    EXCEPT ( DISTINCT ( UNION ( firstTable, SecondTable ) ), Common )
RETURN
    UNION (
        ADDCOLUMNS ( Common, "Unique", "No" ),
        ADDCOLUMNS ( NotCommon, "Unique", "Yes" )
    )

Regards
Zubair

Please try my custom visuals

@__zhe

 

Please see the attached sample file as well

 

 


Regards
Zubair

Please try my custom visuals

Syukron, @Zubair_Muhammad It almost there ..

But I've 2 more question related to this if you are OK 

 

Current DAX, both variable that compared but how to find unique only from 1 column e.g. Serial Number from both table

The result now have "null" but unable to get in query mode to remove this null . Unable relate the data by having null 

@__zhe

 

Please could you copy paste some data with expected result

 

If you could copy paste like this....it will save me time in typing

 

Customer Date Amount
Dave 05-01-18 5
Dave 01-09-18 3
Roy 24-02-18 4
Roy 23-08-18 2

Regards
Zubair

Please try my custom visuals

Hi @Zubair_Muhammad , sorry, jugling with other routine just have chance to reply 

So if we look at the table below, unique will only marked when serial is duplicating , despite the ID or Name is same . Kindly need your advise 

 

Table 1   
IDSerial Name 
A123XXXJohn 
A123YYYAnna 
B123ZZZJohn 
    
Table 2   
IDSerial Name 
A123XXXJohn 
B123VVVJohn 
C123QQQMarrie 
    
Expectation  
IDSerial NameUnique
A123XXXJohnNo
A123YYYAnnaYes
B123ZZZJohnYes
A123XXXJohnNo
B123VVVJohnYes
C123QQQMarrieYes

Hi @__zhe,

 

Please new a calculated table and add a calculated column in it.

Table_3 = UNION(Table_1,Table_2)

Unique = IF(CALCULATE(COUNT(Table_3[Serial ]),ALLEXCEPT(Table_3,Table_3[Serial ]))>1,"No","Yes")

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yulgu-msft table 1 & 2 have different structure, forgotten to mention in the example and also how to nood include null value

Hi @__zhe,

 



table 1 & 2 have different structure, forgotten to mention in the example and also how to nood include null value

As Zubair_Muhammad mentioned in previous reply, you can use SELECTCOLUMNS to deal with this problem.

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.