Product Jan
LowJan
HighJan
VarFeb
LowFeb
HighFeb
VarMar
LowMar
HighMar
VarApr
LowApr
HighApr
VarMay
LowMay
HighMay
VarJun
LowJun
HighJun
VarLow Model Prod A 15 80 -65 97 90 7 80 77 3 74 72 2 25 90 -65 35 99 -64Product Jan Feb Mar Apr May Jun Select1 Prod B 34 68 -34 11 100 -89 84 93 -9 52 43 9 51 64 -13 51 90 -39Prod A 15 97 80 74 25 35Low Prod C 10 24 -14 13 18 -5 93 100 -7 22 50 -28 55 68 -13 78 100 -22Prod B 34 11 84 52 51 51Prod D 78 64 14 52 56 -4 83 62 21 57 14 43 77 95 -18 89 36 53Prod C 10 13 93 22 55 78Select2 Prod D 78 52 83 57 77 89High Mid Model Product Jan Feb Mar Apr May Jun Prod A 60 68 38 45 45 69Prod B 60 68 20 83 59 41Prod C 95 96 25 14 44 49Prod D 31 32 98 82 88 96High Model Product Jan Feb Mar Apr May Jun Prod A 80 90 77 72 90 99Prod B 68 100 93 43 64 90Prod C 24 18 100 50 68 100Prod D 64 56 62 14 95 36
Select models from Data Validation List (Low, Mid or High)
Code:let in Excel.CurrentWorkbook(){[Name="SelectA"]}[Content]Models (tables are renamed suitably)Code:let in Excel.CurrentWorkbook(){[Name="SelectB"]}[Content]
Code:let in Table.UnpivotOtherColumns(Excel.CurrentWorkbook(){[Name="Low"]}[Content], {"Product"}, "Month", "Low")Code:let in Table.UnpivotOtherColumns(Excel.CurrentWorkbook(){[Name="Mid"]}[Content], {"Product"}, "Month", "Mid")Join and calculate variancesCode:let in Table.UnpivotOtherColumns(Excel.CurrentWorkbook(){[Name="High"]}[Content], {"Product"}, "Month", "High")
Code:let All = Table.Combine({Low, Mid, High}), UOC = Table.UnpivotOtherColumns(All, {"Product", "Month"}, "Attribute", "Value"), S1 = Table.ExpandTableColumn(Table.NestedJoin(SelectA,{"Select1"},UOC,{"Attribute"},"Exp",JoinKind.LeftOuter), "Exp", {"Product", "Month", "Value"}), S2 = Table.ExpandTableColumn(Table.NestedJoin(SelectB,{"Select2"},UOC,{"Attribute"},"Exp",JoinKind.LeftOuter), "Exp", {"Product", "Month", "Value"}), Join = Table.NestedJoin(S1,{"Product","Month"},S2,{"Product","Month"},"EXP",JoinKind.LeftOuter), Exp = Table.ExpandTableColumn(Join, "EXP", {"Select2", "Value"}, {"Select2", "Value.1"}), Variance = Table.AddColumn(Exp, "Var", each [Value] - [Value.1], type number), UOSC = Table.Unpivot(Variance, {"Value", "Value.1", "Var"}, "Attribute", "Value.2"), MC = Table.CombineColumns(UOSC,{"Month", "Attribute"},Combiner.CombineTextByDelimiter(" #(lf)", QuoteStyle.None),"Merged"), Value1 = Table.ReplaceValue(MC,"Value.1",MC[Select2]{0},Replacer.ReplaceText,{"Merged"}), Value = Table.ReplaceValue(Value1,"Value",MC[Select1]{0},Replacer.ReplaceText,{"Merged"}), RC = Table.RemoveColumns(Value,{"Select1", "Select2"}) in Table.Pivot(RC, List.Distinct(RC[Merged]), "Merged", "Value.2", List.Sum)
Bookmarks