The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi I have two tables that I am trying to match.
First table has:
Second table has:
I am trying to bring everything from second table to the first and I am matching on basis of 1 (product number aka(Material) 2 Plant.
The only problem is it only bring those items that as well have exactly same plant.
I want to bring back item matched with material and plant, but as well same items even if Plant does not match as long as product number match.
I tried different joint's but results are same.
I as well tried fuzzy matching but it then matches not the same product numbers which is a problem.
The only other solution that I can think of is to only match on product number and ignore plant.
Please let me know if there are any other solutions that I could try.
Solved! Go to Solution.
Hey @Justas4478,
Great choice going with Solution 1! Here's how to filter out Query A records from Query B:
Step-by-Step Implementation:
Query A (Exact Matches):
= Table.NestedJoin(
Table1,
{"Material", "Plant"},
Table2,
{"Material", "Plant"},
"ExactMatch",
JoinKind.Inner
)
Query B (Material-Only Matches, Excluding Query A):
= let
// First, join on Material only
MaterialOnlyJoin = Table.NestedJoin(
Table1,
{"Material"},
Table2,
{"Material"},
"MaterialMatch",
JoinKind.Inner
),
// Create a composite key for Query A records to exclude
QueryA_Keys = Table.AddColumn(
QueryA,
"CompositeKey",
each [Material] & "|" & [Plant]
),
// Create same composite key for current query
WithCompositeKey = Table.AddColumn(
MaterialOnlyJoin,
"CompositeKey",
each [Material] & "|" & [Plant]
),
// Filter out records that exist in Query A
FilteredResults = Table.SelectRows(
WithCompositeKey,
each not List.Contains(
QueryA_Keys[CompositeKey],
[CompositeKey]
)
)
in
FilteredResults
Final Step - Union Both Queries:
= Table.Combine({QueryA, QueryB})
Pro Tip: Add a custom column in each query before union to identify match type:
This way you can easily filter and analyze different match types in your final result!
Fixed? ✓ Mark it • Share it • Help others!
Best Regards,
Jainesh Poojara | Power BI Developer
Why bother matching (also) on plant if you want to bring over matching product numbers even if plant does not match?
Just match on the product number.
Hey @Justas4478,
Great choice going with Solution 1! Here's how to filter out Query A records from Query B:
Step-by-Step Implementation:
Query A (Exact Matches):
= Table.NestedJoin(
Table1,
{"Material", "Plant"},
Table2,
{"Material", "Plant"},
"ExactMatch",
JoinKind.Inner
)
Query B (Material-Only Matches, Excluding Query A):
= let
// First, join on Material only
MaterialOnlyJoin = Table.NestedJoin(
Table1,
{"Material"},
Table2,
{"Material"},
"MaterialMatch",
JoinKind.Inner
),
// Create a composite key for Query A records to exclude
QueryA_Keys = Table.AddColumn(
QueryA,
"CompositeKey",
each [Material] & "|" & [Plant]
),
// Create same composite key for current query
WithCompositeKey = Table.AddColumn(
MaterialOnlyJoin,
"CompositeKey",
each [Material] & "|" & [Plant]
),
// Filter out records that exist in Query A
FilteredResults = Table.SelectRows(
WithCompositeKey,
each not List.Contains(
QueryA_Keys[CompositeKey],
[CompositeKey]
)
)
in
FilteredResults
Final Step - Union Both Queries:
= Table.Combine({QueryA, QueryB})
Pro Tip: Add a custom column in each query before union to identify match type:
This way you can easily filter and analyze different match types in your final result!
Fixed? ✓ Mark it • Share it • Help others!
Best Regards,
Jainesh Poojara | Power BI Developer
Hey @Justas4478,
Based on your requirement to match records from both tables while handling cases where Plant codes don't match exactly, here are several solutions you can implement:
Step 1: Create two separate queries
Step 2: Union both queries to get comprehensive results
Step 1: Perform a left join on Material (Product Number) only Step 2: Add a custom column to categorize matches:
Step 1: Start with your first table as base Step 2: Merge with second table using Material + Plant (Inner Join) Step 3: For unmatched records, perform second merge using Material only Step 4: Combine results from both merge operations
Step 1: Use Fuzzy Matching but set strict similarity threshold (95-100%) Step 2: Apply fuzzy matching only on Material column, not Plant Step 3: Manually verify fuzzy matches to ensure accuracy
= Table.NestedJoin(
Table1, {"Material", "Plant"},
Table2, {"Material", "Plant"},
"ExactMatch",
JoinKind.LeftOuter
)
Then add second join for Material-only matches on unmatched records.
Primary Approach: Use Solution 1 (Union-Based) as it provides:
Alternative: If you need simpler implementation, use Solution 2 with conditional columns to flag match types for easy filtering and analysis.
Fixed? ✓ Mark it • Share it • Help others!
Best Regards,
Jainesh Poojara | Power BI Developer
@jaineshp I am trying to go with Solution 1. I am just unsure how do I filter out query A records from Query B?