Forum

Table.Distinct - wh...
 
Notifications
Clear all

Table.Distinct - what does it remove?

2 Posts
2 Users
0 Reactions
62 Views
(@smallcraig1606)
Posts: 6
Active Member
Topic starter
 

I have a table of data which I have sorted by an ID code (ascending, but that's immaterial), then by a date (descending - that's important). All I want to keep is the latest (most recent) dated record for each ID code.

I'm pretty sure that Excel's "Remove Duplicates" always treats anything after the first as a duplicate (I'd appreciate your confirmation of that, as an aside).

It looks as if "Table.Distinct" doesn't act the same way, at least not consistently. Can you tell me how this function "acts"? By adding an index column, I can get Table.Distinct to act the way I want it to, but I'm interested in knowing how it actually behaves.

Thanks!

Craig

 
Posted : 29/01/2021 8:03 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Craig,

Looking at the official documentation it looks like first keeps the first row (although this isn't explicitly said), removing duplicates of that row that follow - see Example 2

Table.Distinct - PowerQuery M | Microsoft Docs

However I have seen some PQ functions do unexpected things.  If you are getting unexpected results try wrapping the table in Table.Buffer e.g.

Table.Distinct(Table.Buffer(MyTable))

Regards

Phil

 
Posted : 29/01/2021 8:23 pm
Share: