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. ...
  • edhans's avatar
    5 years ago

    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