Forum Discussion
Conditional Merge
- 6 years ago
That is a bit different than what I originally understood. I think a conditional merge is overcomplicating it.
Just do two merges, then some if/then/else logic on nulls.
See the attached file. This is in Excel because it was easier to get your tables loaded from a spreadsheet vs PBIs "Enter Data" screen.\
The lower green table is what you want the result to be. See the queries in Power Query.
I had to change the last record in your first table since you gave me all 71's in the ID RS field, which was a 100% match to the first table. I changed it to 93 and 300030001 for the ID_LOC field.
The following code will conditionally merge with table a or table b.
= if varSeason = "X" then Table.NestedJoin(#"Changed Type", {"Item Number"}, PartAItems, {"Part A Item"}, "ItemWeights", JoinKind.LeftOuter) else Table.NestedJoin(#"Changed Type", {"Item Number"}, PartBItems, {"Part B Item"}, "ItemWeights", JoinKind.LeftOuter)
My conditional tables are PartAItems and PartBItems. Notice I forced the merge column to be ItemWeights vs the normal table name so the expansion always works. Without working through each and every bit of syntax in your statement, it looks like you are incorrectly referring to fields as "field" vs {"field"} in a few places. so Table.NestedJoin isn't getting what it needs as a list in the right places in your first bit of code. The 2nd part looks more correct. So:
Table.NestedJoin(#"Columnas reordenadas16","ID RS",CCunicos,"ID RS", "Prueba", JoinKind.LeftOuter))is the one that looks wrong.
You should probably just manually do the merges separately, then copy and paste the generated Table.NestedJoin statement. Typing all of the brackets, squigley brackets, quotes, commas, etc. manually will drive one to insanity.😀
Or copy and paste my code, then replace with your table and field names.
- Anonymous6 years agoNot applicable
i tried that solution but it didnt work i still get the same error
- edhans6 years ago
Community Champion
Then please post sample data if possible, because it works here.