Consolidate two tables
Table1 Table2 Result YEAR VESSEL NR NET CLAIM YEAR UNDERWRITER SHARE VESSEL NR PREMIUM YEAR UNDERWRITER VESSEL Premium Claim 2017A 1 0 2017X 0,6 A 1 2500 2017X A 2500 0 2017B 2 2000 2017X 0,6 B 2 2750 2017Y A 2850 0 2017B 2 3000 2017X 0,6 C 3 1750 2017X B 5500 5000 2017C 3 0 2018X 0,6 A 1 2900 2017Y B 6200 5000 2018A 1 1750 2018X 0,6 B 2 3150 2017X C 1750 0 2018B 2 3000 2018X 0,6 C 3 2150 2017Y C 2100 0 2018B 2 4000 2019X 0,6 A 1 3500 2018X A 2900 1750 2018B 2 5000 2019X 0,6 B 2 3400 2018Y A 3250 1750 2018C 3 0 2019X 0,6 C 3 4000 2018X B 9450 12000 2019A 1 0 2017Y 0,4 A 1 2850 2018Y B 10500 12000 2019B 2 5000 2017Y 0,4 B 2 3100 2018X C 2150 0 2019C 3 20000 2017Y 0,4 C 3 2100 2018Y C 2500 0 2018Y 0,4 A 1 3250 2019X A 3500 0 2018Y 0,4 B 2 3500 2019Y A 3850 0 2018Y 0,4 C 3 2500 2019X B 3400 5000 2019Y 0,4 A 1 3850 2019Y B 3750 5000 2019Y 0,4 B 2 3750 2019X C 4000 20000 2019Y 0,4 C 3 4350 2019Y C 4350 20000
Code:let Tbl1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], Tbl2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content], Merge = Table.NestedJoin(Tbl1,{"YEAR", "VESSEL", "NR"},Tbl2,{"YEAR", "VESSEL", "NR"},"Tbl2",JoinKind.LeftOuter), Expand = Table.ExpandTableColumn(Merge, "Tbl2", {"UNDERWRITER", "SHARE", "PREMIUM"}, {"UNDERWRITER", "SHARE", "PREMIUM"}), TSC = Table.SelectColumns(Expand,{"YEAR", "UNDERWRITER", "VESSEL", "PREMIUM", "NET CLAIM"}), Group = Table.Group(TSC, {"YEAR", "UNDERWRITER", "VESSEL"}, {{"Premium", each List.Sum([PREMIUM]), type number}, {"Claim", each List.Sum([NET CLAIM]), type number}}), Sort = Table.Sort(Group,{{"YEAR", Order.Ascending}, {"VESSEL", Order.Ascending}, {"UNDERWRITER", Order.Ascending}}) in Sort
Bookmarks