Forum Discussion

David_V's avatar
David_V
Frequent Visitor
8 years ago
Solved

Power Query: Group By function ignore previous sorting

Hello, I've an issue with the group by function. It seems to ignore sorting from previous steps.   Example with a very simple data set (the goal is to keep the latest value for an ID): raw data: ...
  • MarcelBeug's avatar
    8 years ago

    One should always bear in mind that there may be a huge difference between the code steps and the way those code steps are actually evaluated when Power Query executes a query.

     

    Your issue is similar to first sorting a table and next remove duplicates (Table.Distinct): it may be that not the first record will be kept.

     

    Also the solution seems to be similar: buffer the table after sorting (and before grouping).
    This will give you the expected results:

     

    = Table.Buffer(Table.Sort(Source,{{"date", Order.Ascending}}))