Forum Discussion

aseagull's avatar
aseagull
Helper IV
5 years ago
Solved

Does Table.Distinct guarantee it respects order?

Hi. I see on the overview page that List.Distinct is promised to choose the *first* record in a set of equivalent records:

 

But there is no such comment on the Table.Distinct overview page. (And neither of these functions is documented with that behavior on their respective pages.)

 

 

I found a website that declares this is the behavior in its opening paragraph: 

https://www.datalineo.com/post/power-query-sort-distinct-a-quick-tip

 

Is there anything official from the PQ team that guarantees this behavior?

 

Thanks,

Amon

 

  • There is no official statement from MS on this. The URL Greg_Deckler provided is accurate, but if you 100% need to know for a fact that is what happens, you will need to:

    1. Sort your data as desired.
    2. Group by the desired records
    3. Add an index
    4. expand the records
    5. Keep the first one (or last one, or whatever)

    At that point there is no need to run Table.Distinct.

     

    Note that Table.Distinct over an entire table this won't matter, but if you are using the optional columns, then it will.

     

    Table.Distinct(Source) - won't matter

    Table.Distinct(Source, {"Column1"}) - will matter

     

3 Replies

  • edhans's avatar
    edhans
    Community Champion

    There is no official statement from MS on this. The URL Greg_Deckler provided is accurate, but if you 100% need to know for a fact that is what happens, you will need to:

    1. Sort your data as desired.
    2. Group by the desired records
    3. Add an index
    4. expand the records
    5. Keep the first one (or last one, or whatever)

    At that point there is no need to run Table.Distinct.

     

    Note that Table.Distinct over an entire table this won't matter, but if you are using the optional columns, then it will.

     

    Table.Distinct(Source) - won't matter

    Table.Distinct(Source, {"Column1"}) - will matter