Forum Discussion

jhartranft60's avatar
jhartranft60
Advocate IV
6 years ago
Solved

How do I buffer my table in Power Query?

In Power Query, I'm trying to sort a table and remove duplicates.  The table sort is to ensure that the record I want to keep is first in the table and all subsequent records will come later and be r...
  • Cmcmahan's avatar
    6 years ago

    I haven't tested it, but it looks like you just need to add Table.Buffer to force PowerQuery to actually sort the table before duplicate removal.  Otherwise, PowerQuery has a tendency to try and be too efficent, in this case, removing a bunch of rows and sorting the smaller dataset, which is great from a performance standpoint.

     

    You should be able to update your advanced query with the items in blue:

    #"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Application Date", Order.Descending}}),
    #"Buffer Sorted Table" = Table.Buffer(#"Sorted Rows"), 
    #"Removed Duplicates" = Table.Distinct(#"Buffer Sorted Table", {"DSI"}),

    If this doesn't make sense, or doesn't actually work, you can try the solution that was talked about in message #6 of the thread you linked.  That method is going through and finding the distinct rows yourself instead of letting Table.Distinct do it for you (and potentially get it wrong)