Code:
// Table1P
let
Base = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
RCC = Table.RemoveColumns(Base,{"Financial Statement", "Main Sub", "Detailed Sub"}),
USC = Table.Unpivot(Source, Table.ColumnNames(RCC), "Year", "Value"),
RR = Table.ReverseRows(USC),
Distinct = Table.Distinct(RR, {"Year"}),
Asc = Table.Sort(Distinct,{{"Year", Order.Ascending}}),
TSC = Table.SelectColumns(Asc,{"Year", "Value"}),
PT = Table.Pivot(TSC, List.Distinct(TSC[Year]), "Year", "Value"),
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Index = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
UOC = Table.UnpivotOtherColumns(Index, {"Financial Statement", "Main Sub", "Detailed Sub", "Index"}, "Year", "Value"),
TSAsc = Table.Sort(UOC,{{"Year", Order.Ascending}, {"Index", Order.Ascending}}),
RC = Table.RemoveColumns(TSAsc,{"Index"}),
Idx = Table.AddIndexColumn(RC, "Index", 0, 1, Int64.Type),
Divide = Table.AddColumn(Idx, "Divide", each Idx{[Index]}[Value]/TSC{[Year=[Year]]}[Value]),
Grp = Table.Group(Divide, {"Year"}, {{"Count", each _, type table [Financial Statement=text, Main Sub=text, Detailed Sub=text, Year=text, Value=number, Index=number, Divide=nullable number]}}),
Suffix = Table.TransformColumns(Grp, {{"Year", each _ & "V", type text}}),
Lst = Table.AddColumn(Suffix, "Lst", each [Count][Divide]),
RCCount = Table.RemoveColumns(Lst,{"Count"}),
Ext = Table.TransformColumns(RCCount, {"Lst", each Text.Combine(List.Transform(_, Text.From), "="), type text}),
Split = Table.SplitColumn(Ext, "Lst", Splitter.SplitTextByDelimiter("=", QuoteStyle.Csv), {"Lst.1", "Lst.2", "Lst.3", "Lst.4", "Lst.5", "Lst.6", "Lst.7", "Lst.8", "Lst.9", "Lst.10", "Lst.11", "Lst.12"}),
Dec = Table.TransformColumnTypes(Split,{{"Lst.1", type number}, {"Lst.2", type number}, {"Lst.3", type number}, {"Lst.4", type number}, {"Lst.5", type number}, {"Lst.6", type number}, {"Lst.7", type number}, {"Lst.8", type number}, {"Lst.9", type number}, {"Lst.10", type number}, {"Lst.11", type number}, {"Lst.12", type number}}),
Trans = Table.Transpose(Dec),
Promo = Table.PromoteHeaders(Trans, [PromoteAllScalars=true]),
AddIndex = Table.AddIndexColumn(Promo, "Index", 1, 1, Int64.Type)
in
AddIndex
Bookmarks