Nested joins and expansion
Count matches before expanding
Table.NestedJoin places a table of matches into each retained row. With a left outer nested join, the outer table retains the original left row count, even if a lookup key matches multiple right rows. Expanding can multiply rows; a duplicated dimension key may turn one sale into several copies. Audit zero, one and multiple matches before expansion. Do not select an arbitrary first duplicate or use distinct on the expanded result to conceal an ambiguous lookup. All M examples are standalone expressions for a blank query in a disposable Power BI Desktop Import lab. No credentials, external connector or paid service are required. Outputs are predictions; native M execution and exact Desktop build are NOT RUN. Treat row order as unspecified unless explicitly sorted.
Expose a duplicate rather than multiplying money
let Sales = #table(type table [LineID=text, ProductKey=text, RevenueUSD=number], {{"L1","P01",40},{"L2","P02",25},{"L3","P99",15}}), Products = #table(type table [Key=text, Category=text], {{"P01","Desk"},{"P01","Office"},{"P02","Lamp"}}), Nested = Table.NestedJoin(Sales,{"ProductKey"},Products,{"Key"},"Matches",JoinKind.LeftOuter), Audit = Table.AddColumn(Nested,"MatchCount",each Table.RowCount([Matches]),Int64.Type), Accepted = Table.SelectRows(Audit,each [MatchCount]=1), Rejected = Table.SelectRows(Audit,each [MatchCount]<>1), Fact = Table.ExpandTableColumn(Accepted,"Matches",{"Category"},{"ProductCategory"})in [Audit=Audit, Fact=Fact, Rejected=Rejected]Match counts L1=2, L2=1, L3=0. Accepted: L2, 25 USD. Rejected: L1 and L3, 55 USD. The input total 80 equals accepted plus rejected. A naive left expansion repeats L1 twice and leaves L3 unmatched: four rows, 120 USD. An inner expansion would drop L3 but still duplicate L1: three rows, 105 USD. Retain the nested audit for diagnosis. The new column name ProductCategory makes its origin explicit; selecting specific columns avoids importing unrelated lookup attributes.
Resolve duplicates at their source
let Products = #table(type table [Key=text, Category=text], {{"P01","Desk"},{"P01","Office"},{"P02","Lamp"}}), Counts = Table.Group(Products,{"Key"},{{"Rows",each Table.RowCount(_),Int64.Type}}), Conflicts = Table.SelectRows(Counts,each [Rows]>1), Corrected = #table(type table [Key=text, Category=text], {{"P01","Desk"},{"P02","Lamp"}}), Sales = #table(type table [LineID=text, ProductKey=text, RevenueUSD=number], {{"L1","P01",40},{"L2","P02",25},{"L3","P99",15}}), Orphans = Table.NestedJoin(Sales,{"ProductKey"},Corrected,{"Key"},"Matches",JoinKind.LeftAnti)in [Conflicts=Conflicts, Orphans=Orphans]Conflict P01 has two rows. Corrected is an illustrative replacement approved by the fictional product owner, not the output of automatic deduplication. After that replacement, L1 and L2 are uniquely matched (65 USD), while L3 is still orphaned (15 USD). A source uniqueness constraint is preferable when the business key must be unique. If categories actually change over time, the model needs a versioned key and effective-date rule; arbitrarily retaining a record can assign history to the wrong category.
Validate at the original fact grain
Compare distinct LineID count, row count, total revenue and per-line multiplicity before and after expansion. A matching grand total alone can hide offsetting lost and duplicated rows. Use anti joins for missing dimension keys and group counts for duplicate dimensions. A mandatory product lookup can quarantine non-unique and missing matches; an optional enrichment might preserve unmatched lines under a documented Unknown member policy. Reject records must remain traceable and visible to the data owner.
Practice: correct a dimension, not the money
Using example one, replace both P01 rows with a single approved P01 row. Add a valid P99 row. Predict the accepted and rejected counts and total revenue. Explain why a financial total must not depend on dimension duplicate count.
Official reading
nestedjoin · expand · merge · join