Merge query pulls wrong data from reference table in power query

Chandan Rao 20 Reputation points
2025-12-16T16:38:07.8433333+00:00

Check the screenshot where data is 26-05-2025 in main sheet and in merge sheet the data is pulled using merger query but resultant date is 21-04-2025 why? I have asked it with chatgpt also and it says its the way it is designed. What I understand is that after merge query it re-evaluates all steps and disregard the sorting order and then apply remove duplicate and pulls the result. in the main sheet i have applied sorting in descending order step. I have been using power query for more than a year and never doubted it, but this time it hits me. Imagine I need to calculate interest based on date pulled from another sheet and it pulls earlier date and I end up paying more on interest as it would calculate from 21-04-2025 and not from 25-05-2025. This is a serious issue that has questioned my faith in power query. I have always been confident regarding excel calculation and working until now.Merge

Main Sheet

Microsoft 365 and Office | Excel | For home | Windows
{count} votes

Answer accepted by question author
  1. Ashish Mathur 100.9K Reputation points Volunteer Moderator
    2025-12-18T00:05:03.59+00:00

    Hi,

    In the Main sheet, add this last step

    Table.Buffer(#"Removed Duplicates")
    

    User's image

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Aron 7,680 Reputation points Independent Advisor
    2025-12-16T17:16:19.02+00:00

    I get how concerning this feel, and I want to help you lock this down reliably.

    The issue comes from how Power Query handles row order and duplicates: when you use Remove Duplicates after a sort, the engine can re-evaluate and reorder during a Merge, so Table.Distinct may keep the first row in a new order, pulling the earlier date instead of the latest.

    To make this deterministic, group by the key (e.g., Car) and return List.Max([Date]) as “LatestDate,” then merge to that aggregated query; or, if you prefer Sort + Distinct, add Table.Buffer right after the sort and before Table.Distinct to lock the order.

    As a quick check, add a Group step to your Main Sheet, confirm the LatestDate per car, and re-run the merge.

    If you still need the entire latest record, use Table.Group with Table.Max(_, "Date") instead of just the date.

    Can you share the M code for your Main and Merge queries and confirm whether your source is folding (e.g., coming from Excel vs. a database)?

    Also, do you need only the date or the full latest row for interest calculations?

    Regards,
    Aron


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.