In practice7 min read

Two exports, an extra thousand: check AI-assisted table joins

Combine orders and order lines without inflating totals: keys, match counts, unmatched records and a worked UAH 2,400 versus UAH 3,400 reconciliation.

Prepared by the NADALI editorial team using AI

A person checks paper calculations with a calculator at a desk beside a laptop.
Pavel Danilyuk / Pexels, photo 7654591. https://www.pexels.com/photo/a-person-using-calculator-7654591/ . Illustrative stock photograph; not a Nadali test or an actual dataset from this guide. · Pexels License https://www.pexels.com/license/ . Free website and editorial use and modification permitted; no endorsement implied. Source photograph and license checked 2026-11-16. · 1440 × 960

Author: Nadali. Prepared with AI assistance.

A shop has an orders export and a separate file of order lines. AI combines them and calculates sales. The report gains an extra UAH 1,000 without changing a single original cell: one order’s total appears beside each of its lines.

In brief: before combining tables, define what one row represents, which key connects the records and how many matches are allowed. Afterwards, reconcile counts, keys, amounts and unmatched records. This guide is for a shop or service-business owner reviewing a report prepared by an analyst or AI. The deliverable is a checked table with a short reconciliation record, rather than a polished total alone.

1. Start with the question and unit of record

Write down the intended result: for example, the total amount of completed orders for a specified day and their number of order lines. Do not call this accounting revenue without the appropriate definition. Payment, order completion and revenue recognition can fall on different dates.

Explain one row in each file. In the first, it might represent an order; in the second, one order line. Four rows in the second file do not necessarily mean four sales. Record the period, time zone, branches, statuses, currency and export time. Two files named “November” may cover different boundaries.

Keep the originals. Work with authorised copies without unnecessary customer names, addresses or contact details. Column definitions and an invented sample are enough for the initial AI brief.

2. Check the key, not similar-looking names

A key is the field or set of fields that establishes the intended match. An order number might be unique only within a branch, requiring both fields. A product name or customer surname is usually an unreliable substitute. Similar wording does not prove that records describe the same transaction.

Before combining files, count rows, distinct keys and missing keys in each. Investigate repeats: two lines belonging to one order are normal, while two unexplained versions of an order header may be a problem. Do not delete them automatically.

Specify the expected relationship: one-to-one, one-to-many or many-to-one. When a key repeats in both files, the number of pairs can grow sharply. Two rows on the left and three on the right for the same key produce six matches. That is join arithmetic, not evidence of six business events.

3. Agree which records must survive

The PostgreSQL documentation explains that an inner join retains matching pairs, while a left outer join also preserves unmatched left-hand rows. A left join does not guarantee an unchanged row count: multiple matches on the right still produce multiple pairs.

For a register of all selected orders, keep those orders as the base and flag missing detail. Also produce a separate list of lines whose orders are absent from the selected order file. Otherwise, records can disappear from scrutiny simply because the other file lacks a matching key.

Do not match missing keys as “unknown equals unknown.” Put those records into a separate review queue and establish why the identifiers are missing.

4. Worked example: UAH 2,400 becomes UAH 3,400

All records below are invented. The first table has one row per order. Amount is a hypothetical order measure in hryvnias, without any claim about tax or accounting treatment.

Order Status Amount, UAH
O101 Completed 1000
O102 Completed 800
O103 Cancelled 600
O104 Completed 600

The second table contains order lines. Each line ID is unique; order IDs can repeat.

Line Order Line amount, UAH
L1 O101 600
L2 O101 400
L3 O102 800
L4 O103 600
L5 O999 200

For our question, completed orders O101, O102 and O104 total 1,000 + 800 + 600 = UAH 2,400. Left-joining these three orders to the lines produces four rows: two for O101, one for O102 and one for O104 without a line.

Summing the order-amount column in this expanded table gives 1,000 + 1,000 + 800 + 600 = UAH 3,400. Repeating O101’s full amount causes the UAH 1,000 overstatement; no additional sale occurred. There are still three distinct order IDs. Checking distinct IDs alone does not catch the inflated sum.

An inner join would cause another problem: O104 would disappear altogether. L5, linked to O999, also needs investigation. Its order could be outside the period, in another branch or missing from the export. Automatically declaring this line erroneous would be unjustified.

5. Preserve the required level of detail

If the final report needs one row per order, first summarise the lines by the agreed key. Include a line count and line-amount total, then join that summary to the orders. Check that the resulting right-hand dataset has no more than one row per key.

In the example, this preserves three completed-order rows and their UAH 2,400 total. O101’s lines total UAH 1,000 and O102’s total UAH 800. O104’s line amount is not established from the supplied detail, rather than proven to be zero. Matched detail covers two of the three completed orders, amounting to UAH 1,800. UAH 2,400 is correct for the header table, but reconciliation of all its components remains incomplete.

If the report is deliberately at line level, retain that level and sum line measures. Do not allocate delivery charges, discounts or another order-level amount to products without an agreed rule. Do not repair an inflated result by removing “identical amounts”: different orders can have the same value.

6. Keep exceptions and statuses separate

In our example, O103 is excluded from the completed-order measure, while L4 remains a line linked to a cancelled order. It is not unmatched. L5 is a separate line without a matching header; O104 is a header without lines. The reconciliation record should show all three situations, their counts and amounts.

Agree rules for refunds, partial cancellations and repeated record versions before calculation. Do not substitute a current status for the status at a historical date when the report needs the latter. Set unknown statuses aside for review. Any selection rule must leave an explainable bridge from the initial amount to the final one.

7. Give AI a brief you can verify

A working brief: “Explain the unit of record in each file. Propose an explicit key and check its missing and repeated values. Show the expected number of matches. Preserve every selected order; separately list unmatched records and excluded statuses. Do not delete repeats or replace unknowns with zero. Return the transformation steps and count and amount checks before and after each step. Change nothing in the source system.”

An analyst can implement this with existing tools. Microsoft describes Power Query merges using one or several columns; their data types must match, and components of a composite key must be selected in corresponding order. Check the result after expanding the nested table, not just the estimated matches in its preview.

For pandas, the merge documentation describes relationship validation through validate and row-origin labels through indicator. The many_to_many option performs no uniqueness checks; null keys can match each other. A parameter name does not replace business verification. We did not test this workflow in a user’s account or in the Power Query interface.

8. Accept the result with its reconciliation record

Before using the report, the responsible person checks:

  • What each final row represents and whether its key is unique.
  • Row and key counts before and after the join.
  • Which amounts can be summed at this level of detail.
  • Which records are unmatched, excluded by rule or have an unknown state.
  • Whether control totals reconcile by branch and status, not only overall.
  • Whether originals, rules, the result version and unresolved questions are retained.

Stop the final conclusion if a relationship or discrepancy remains unexplained. A clearly labelled incomplete report is more useful than a precise-looking invented total. A new field, different export or changed status rules requires another reconciliation.

Read also: preserving data during CSV import and when zero does not establish an absence of activity.

Sources read on 16 November 2026. The process and teaching tables are original editorial proposals. The example’s arithmetic was checked with a separate local calculation; this is not a test of a real business or AI quality. The data owner must confirm access to the necessary exports and the meaning of their fields. Applying the principle does not itself require a new paid platform. 

Sources and verification

  1. PostgreSQL documentation: Table Expressions, joined tables ↗
    Source checked: 2026-11-16
  2. Microsoft Learn: Merge queries overview, Power Query ↗
    Source checked: 2026-11-16
  3. pandas documentation: pandas.merge ↗
    Source checked: 2026-11-16