Forum Discussion

ELIU's avatar
ELIU
Helper II
1 year ago
Solved

Group by Columns malfunction

Hi,   I wanted to be able to group by columns Project Name, Project ID and Project Date to be able to sum up the Expense column. However, after the Group by is applied, the total Expense for each u...
  • DataNinja777's avatar
    DataNinja777
    1 year ago

    Hi ELIU ,

     

    It’s interesting that sorting by Project Name before applying Group By resolves the issue. This suggests that the problem is related to how Power Query processes the data when it’s unsorted. One possible explanation is that if your data source is a live database, API, or an Excel file that gets refreshed frequently, the order of rows may change with each refresh. Some transformations in Power Query, such as Merges, Expands, or Joins, can cause row order to change, which might lead to unintended duplications in aggregation if Power Query processes rows differently each time.

    Another possibility is that Power Query applies implicit indexing when processing data, and when the rows are unordered, the Group By step may treat some values inconsistently. Sorting ensures that identical Project Name + Project ID + Project Date records appear consecutively, avoiding any discrepancies. Additionally, hidden formatting issues may be causing unintended duplicates. Even if the values appear the same, they may have leading/trailing spaces, data type mismatches, or invisible characters. Sorting could be forcing Power Query to normalize how it reads these values, making it treat them consistently. You can remove any hidden inconsistencies by applying a Trim & Clean step before grouping:

    = Table.TransformColumns(Source, {{"Project Name", Text.Trim, type text}})
    

    It’s also worth considering that Microsoft occasionally updates Power Query’s internal optimizations, and if a recent update modified how it processes Group By operations on unordered data, that might explain why the behavior changed suddenly. To prevent this issue in the future, you can keep sorting Project Name before applying Group By and ensure that all grouping columns have consistent data types (Text, Number, Date). If your data comes from an external source, checking for any recent structural changes might also help in identifying the root cause.

     

    Best regards,