Code:
// Table1
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Locale = Table.TransformColumnTypes(Source, {{"Date of initiation", type date}}, "en-US"),
Year = Table.AddColumn(Locale, "Year", each Date.Year([Date of initiation]), Int64.Type),
Index = Table.AddIndexColumn(Year, "Index", 1, 1),
Grp = Table.Group(Index, {"Year"}, {{"Count", each _, type table}}),
Sort = Table.TransformColumns(Grp,{{"Count", each Table.AddIndexColumn(Table.Sort(_, "Index"),"GroupIndex")}}),
Exp = Table.ExpandTableColumn(Sort, "Count", {"Site", "Date of initiation", "Record number", "Index", "GroupIndex"}, {"Site", "Date of initiation", "Record number", "Index", "GroupIndex"}),
PlusOne = Table.TransformColumns(Exp, {{"GroupIndex", each _ + 1, type number}}),
FD = Table.FillDown(PlusOne,{"Record number"}),
EFC = Table.TransformColumns(FD, {{"Record number", each Text.Start(_, 7), type text}}),
Prefix = Table.TransformColumns(EFC, {{"GroupIndex", each "-000" & Text.From(_, "en-GB"), type text}}),
TCC = Table.CombineColumns(Table.TransformColumnTypes(Prefix, {{"Year", type text}, {"GroupIndex", type text}}, "en-GB"),{"Record number", "Year", "GroupIndex"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Record numbers"),
Date = Table.TransformColumnTypes(TCC,{{"Date of initiation", type date}}),
Rem = Table.RemoveColumns(Date,{"Index"})
in
Rem
Bookmarks