(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to combine tables with partial keys in Power BI: step by step

João Barros 24 de November de 2026 4 min read

Learn how to combine tables in Power BI when join keys don’t match exactly — for example, when a column contains codes with prefixes or spaces. This technique is useful to merge systems that don’t have normalized keys, avoiding extensive manual cleaning.

Prerequisites

  • Power BI Desktop installed (recent version).
  • An Excel or CSV file with two sample tables (sales and catalog) or access to equivalent data.
  • Basic knowledge of Power Query (Query Editor) and M formulas.

Step 1: Load the tables into Power Query

Import the two tables: for example, Sales (column OrderCode) and Catalog (column SKU). Open "Transform data" to enter Power Query and review the columns that will be used for the join.

Step 2: Normalize text in both tables

It’s important to remove spaces, convert to uppercase, and strip common characters that hinder comparison. Do this in each query.

// Exemplo M para normalizar: adicionar coluna NormalizedKey
= Table.AddColumn(Origem, "NormalizedKey", each Text.Upper(Text.Trim(Text.Replace([OrderCode], "-", ""))), type text)

Replace [OrderCode] with the column name and adapt Text.Replace for other characters if needed.

Step 3: Extract the comparable key fragment

If only part of the code matches (for example, the last 6 characters), create a column with that fragment. This will be used for the merge.

// Exemplo: obter os últimos 6 caracteres
= Table.AddColumn(#"Tabela Normalizada", "KeyFragment", each Text.End([NormalizedKey], 6), type text)

For prefixes use Text.Start, to remove suffixes use Text.BeforeDelimiter, etc.

Step 4: Repeat normalization/fragment on the catalog table

Apply the same process (normalization and creation of KeyFragment) to the Catalog table to ensure the two columns are comparable.

Step 5: Perform the Merge with partial key

In Power Query, select the Sales query and click Home > Merge Queries. Select the KeyFragment column in both queries. Choose the appropriate join type (Left Outer to keep all sales).

Step 6: Expand and validate catalog columns

After the merge, expand the desired columns from Catalog (e.g., Description, Category). Confirm that rows were associated correctly and resolve multiple matches if they occur.

Step 7: Handle multiple matches and unmatched entries

Common issues: multiple SKUs with the same fragment or null values. For multiple matches you can:

  • Keep the first match (Table.First) when creating a custom column.
  • Concatenate Catalog values to view options (Text.Combine).
// Exemplo: criar coluna que pega o primeiro item da lista do merge
= Table.AddColumn(#"Merged", "Catalogo_First", each if List.Count([Catalogo])>0 then [Catalogo]{0}[Descricao] else null)

For unmatched entries, add columns that identify nulls and prepare additional cleaning or a manual review process.

Step 8: Performance and best practices

Text operations and merges can be slow on large tables. Some suggestions: reduce columns before the merge, apply normalization before any expansion, and use indexes to check duplicates. Avoid queries that recreate expensive columns multiple times.

Verify the result

In the Power BI data view check some key rows: 1) Sales rows with Catalogo_First populated; 2) count of nulls in the match column; 3) examples of multiple matches. Use a table visual with OrderCode, KeyFragment, Catalogo_First and a filter to show nulls or multiple matches.

Conclusion

Combining tables with partial keys in Power BI is a practical way to integrate imperfectly normalized systems without full normalization. Next steps: automate cleaning with reusable M functions or try fuzzy merge (Merge Queries > Use fuzzy matching) when fragments aren’t exact. Tip: always test with samples before applying to the entire dataset to avoid surprises.