Reliable Joins and Data Integrity
A practical lesson on preparing tables, choosing joins, and checking data integrity before loading a report.
Start with and keys
Establish what a row represents
Before combining tables, identify each table’s : what one row represents. For example, a sales table might have one row per product per month, while a product table might have one row per product. If the grains are misunderstood or incompatible, a merge can create unexpected duplicates even when the selected columns look like reasonable matches.
A wide cross-tab may need reshaping first. The source example has columns ProductID, Jan, and Feb. Unpivoting the month columns produces ProductID, Month, and Sales, with one row for each product-month observation. The intended is now one row per product per month, and the key that identifies that is ProductID + Month. In Power Query, Unpivot Other Columns is useful when identifier columns are known but additional measurement columns might be added later.
Choose and prepare keys by meaning
A is one or more columns that identify corresponding records. Select columns because they represent the same concept in the two tables, not just because their names look alike. For instance, a product identifier in a sales table might correspond to a product identifier in a product table. If an identifier is unique only within a store, ProductID alone is not enough: use both StoreID and ProductID to distinguish records.
For a multi-column key, pair corresponding columns in the same order on both sides. Column names may differ, but each selected pair must have the same meaning. For example, a store identifier must be paired with a store identifier, and a product identifier with a product identifier.
Prepare the values as well as the column choices. Use compatible data types on both sides, and check for null or blank keys, extra spaces, inconsistent capitalization, and differently formatted values. In Power Query, corresponding join columns need the same data type for reliable matching. These checks make it less likely that records intended to correspond will be treated as unmatched.
Choose the join and understand its effects
Choose which rows the result must preserve
Select a based on the output you need, especially what should happen to rows without a match:
Left outer keeps every row from the left table and adds matching right-side data. Use it when all left-side records must remain, such as preserving all sales while adding product details where available.
Inner keeps only rows that match on both sides. Choose it only when excluding unmatched records is intended.
Full outer keeps rows from both tables, matching them where possible. It can help reconcile two sources and examine what appears in only one.
Left anti returns left-side rows with no right-side match; for example, it can expose sales whose product key is missing from the product table.
Right anti returns right-side rows with no left-side match; for example, it can show product records unused by sales.
Right outer keeps every right-side row and matching data from the left.
In Power Query, a merge initially includes a nested column for the matching table. Expand only the fields you need in the result.
Check how keys occur on each side
A join’s describes how often keys occur in the two tables:
One-to-one: each key occurs once in each table.
Many-to-one: a key may repeat on the left but occurs once on the right. This is common when multiple transactions refer to one product.
One-to-many: one left-side record matches multiple right-side records. This may be intended, but it expands rows.
Many-to-many: keys repeat on both sides. Matches can multiply rows and usually need investigation.
If the report expects a many-to-one relationship, check that the right-side lookup key is unique. Group the lookup table by key and count its rows; any count above one is a duplicate-key exception. Do not simply remove duplicates to make the merge appear to work. Decide which record is correct, or revise the key or table .
Also measure match coverage. In the source example, 980 of 1,000 sales rows match a product, so the left-side match rate is . That percentage does not make the remaining rows unimportant: even a small unmatched group may contain a high-value record. Inspect unmatched left-side records directly with a left anti join. Choose the and investigate its consequences before treating the merged result as ready.
Validate before loading
Treat the merge as unapproved until checked
A successful merge operation does not by itself show that the result is correct. Validate it against the expected row meaning, coverage, data quality, and business results before loading it.
Compare row counts. For a left outer many-to-one join, the result should normally have the same number of rows as the left table. More rows can indicate duplicate keys on the right; fewer rows can indicate that an inner join or a filter dropped records.
Check keys at the intended output . If each product-month should appear once, verify that
ProductID + Monthdoes not occur more than once. This is especially important after unpivoting measurements into product-month rows.Inspect unmatched records. Use anti joins in both directions when coverage in both tables matters. Classify missing keys as expected, correctable, or blocking errors rather than silently discarding them.
Profile key and output columns. Look for blanks, invalid values, errors, and unusual distributions. Power Query profiling can show column quality, value distributions, distinct values, and values occurring only once. It may default to the first 1,000 rows; use the entire dataset when validating the full input.
Compare business controls. Check totals or other relevant control figures before and after the merge. Matching row counts cannot detect every incorrect match.
Make checks repeatable
For a recurring report, keep validation as explicit query steps or documented refresh criteria. Record expected row counts, key rules, and acceptable unmatched rates, then investigate exceptions. Clear step names and consistent data types also make a Power Query workflow easier to maintain.
For example, suppose a sales table initially has one row per product, with monthly sales in separate columns, and a product table should have one row per ProductID. Unpivot the monthly columns so sales has one row per product per month, then confirm that the product table has no repeated product keys. Merge with a left outer join to preserve all sales rows. Expand the product description, compare the result’s row count with the unpivoted sales row count used in the merge, and use a left anti join to review sales with no product match. If the merged row count increases, stop and investigate duplicate product keys before loading the report.
: Reviewing a merged result to confirm that it preserves the intended records and produces trustworthy output.