Forum Discussion
Combining 2 tables both have duplicate values, need help!
- 9 months ago
Attached is the Excel File as I set it up with the Power Query
And here is another method that seems to handle entries that are in one table but not the other, with or without data for the respective entries:
let
CostTbl = Table.Group(Cost, {"Item"}, {
{"Costs", each Table.AddIndexColumn(_,"Index",0,1),
type table [Item=nullable text, Cost=Int64.Type, Index=Int64.Type]}}),
#"Rename Cost Item" = Table.RenameColumns(CostTbl,{"Item","CostItem"}),
OrderTbl = Table.Group(Order, {"Item"}, {
{"Orders", each Table.AddIndexColumn(_,"Index",0),
type table [Item=nullable text, Units=Int64.Type, Index=Int64.Type]}}),
Join = Table.Join(#"Rename Cost Item","CostItem",OrderTbl,"Item",JoinKind.FullOuter),
#"Removed Columns" = Table.RemoveColumns(Join,{"CostItem", "Item"}),
//blank table used in next step
x=#table({"Units","Orders","Cost"},{{null,null,null}}),
#"Added Custom" = Table.AddColumn(#"Removed Columns", "Cost+Orders",
each Table.Combine({[Costs]??x,[Orders]??x}), type table),
#"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Costs", "Orders"}),
#"Group Tables" = Table.TransformColumns(#"Removed Columns1",{"Cost+Orders",
each Table.Group(_,"Index",{
{"Item", (t)=>List.RemoveNulls(t[Item]){0}?},
{"Units", (t)=>List.RemoveNulls(t[Units]){0}?},
{"Cost", (t)=>List.RemoveNulls(t[Cost]){0}?}
}), type table[Item=text,Cost=Int64.Type,Units=Int64.Type]}),
#"Expanded Cost+Orders" = Table.ExpandTableColumn(#"Group Tables", "Cost+Orders", {"Item", "Units", "Cost"}),
#"Removed Blank Rows" =
Table.SelectRows(#"Expanded Cost+Orders", each
not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null})))
in
#"Removed Blank Rows"
Hi Ron, thank you for your reply. Can I get your PBIX or Power Query file with steps so that I can follow. I'm not very good with code. Sorry for your inconvenience, I really appreciate your help.
- ronrsnfld9 months agoSuper User
It'll take me a while to separate it out. It is on an Excel Sheet that has lots of other stuff in the workbook.
But here are some steps to follow.
Make sure your first table is named Cost.
Make sure your second table is named Order.
Select `Data => from Table` for each of those two tables.
After the PQ UI opens, select `Close and Load to` ==> `Connection Only`.
Then return to the PQ Editor and select a New Query with Source = Blank.
Go to the Advanced Editor and paste the code into the Advanced Editor, replacing everything that might be there.
- SAM_1300318 months agoFrequent Visitor
Took a while, but i managed to add some columns for my report, worked great. I learned a lot, thank you, you guys helped me a ton—my sincere appreciation to everyone for their help.
- ronrsnfld9 months agoSuper User
Attached is the Excel File as I set it up with the Power Query