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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
aseagull
Helper IV
Helper IV

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:

aseagull_1-1621869348669.png

 

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.)

 

aseagull_0-1621869327605.png

 

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

 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

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

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

3 REPLIES 3
edhans
Super User
Super User

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

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thank you Greg and Edhans both. 

Greg_Deckler
Super User
Super User

@aseagull There is a whole discussion thread around this topic here: Which row will keep Table.Distinct(Table, {"Column... - Microsoft Power BI Community

 

There is an "official" answer from a v- if you scroll all the way down.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors