Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Duplicates returned with Table.Distinct in M Query

Hi,

I am trying to create a table containing only distinct rows from the union of two existing Power Query tables in Excel.

 

My code (anonymised) is:

let
    SelectColumnsT1 = Table.SelectColumns(T1Data,{"Field1", "Field2", "Field3"}),
    SelectColumnsT2 = Table.SelectColumns(T2Data,{"Field1", "Field2", "Field3"}),
    CombineBoth = Table.Combine({SelectColumnsT1 , SelectColumnsT2 }),
    GetDistinct = Table.Distinct(CombineBoth,{"Field1", "Field2", "Field3"})
in
    GetDistinct

Field1 is an integer and the other fields are strings.

This returns duplicates in the resulting table.  I have checked the individual rows which are duplicates and there are no leading/trailing blanks, and when I check within excel that the fields in the duplicated rows are equal, the result is TRUE.

 

Am I misunderstanding the use of Table.Distinct?

Have I got the syntax wrong?

Is there a bug in this function?

Any other possible things I should look into to try to get to the bottom of this?

 

I would be grateful if anyone can give me any help on this.

 

Regards,

Mark

  • Anonymous's avatar
    Anonymous
    7 years ago

    Hi v-yulgu-msft,

    Thanks for replying.

    I duplicated this post in "Microsoft Power BI Community / Forums / Get Help with Power BI / Desktop" since I think I created this post in the wrong section.

    Anyway, after a little more work my conclusion was:

     

    <<I have experimented on using an up to date version of Excel (my office uses Excel 2013, my personal laptop has the latest Excel 365).

    The problem disappears on my version of Excel, so I think maybe I've uncovered a bug in the old version, which I guess I can't get around.>>

     

    Regards,

    Mark

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi v-yulgu-msft,

    Thanks for replying.

    I duplicated this post in "Microsoft Power BI Community / Forums / Get Help with Power BI / Desktop" since I think I created this post in the wrong section.

    Anyway, after a little more work my conclusion was:

     

    <<I have experimented on using an up to date version of Excel (my office uses Excel 2013, my personal laptop has the latest Excel 365).

    The problem disappears on my version of Excel, so I think maybe I've uncovered a bug in the old version, which I guess I can't get around.>>

     

    Regards,

    Mark

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi Anonymous ,

     

    I tested above code on my side, after applying the last step "Table.Distinct", no duplicated rows were shown.

     

    In your scenario, after loading T1Data and T2Data into desktop, right click columns, choose "Transform->Clean" to clear invisible characters.

     

    Best regards,

    Yuliana Gu