let
Source = Excel.CurrentWorkbook(){[Name="tblProjects"]}[Content],
allColumns.Type = Table.TransformColumnTypes(Source,{{"Budget ID", type any}, {"Project Name", type text}, {"Renamed", type text}, {"Division/Department", type text}, {"Project Manager", type text}, {"Spending Geometry", type text}, {"Status", type text}, {"Est. Start Date", type date}, {"Est. End Date", type date}}),
activeProjects.Filter = Table.SelectRows(allColumns.Type, each ([Spending Geometry] = "Linear") and ([Status] = "Deferred" or [Status] = "Future" or [Status] = "In Progress")),
startDate.Sort = Table.Sort(activeProjects.Filter,{{"Est. Start Date", Order.Ascending}}),
monthsDuration.Add = Table.AddColumn(startDate.Sort, "Duration", each ([Est. End Date]-[Est. Start Date])/30.5),
duration.Type = Table.TransformColumnTypes(monthsDuration.Add,{{"Duration", Int64.Type}}),
today.Add = Table.AddColumn(duration.Type, "Today's Date", each DateTime.LocalNow()),
today.Type = Table.TransformColumnTypes(today.Add,{{"Today's Date", type date}}),
monthsLeft.Add = Table.AddColumn(today.Type, "Months Remaining", each ([Est. End Date]-[#"Today's Date"])/30.5),
monthsLeft.Type = Table.TransformColumnTypes(monthsLeft.Add,{{"Months Remaining", Int64.Type}}),
pctCPt.Add = Table.AddColumn(monthsLeft.Type, "Percentage Complete", each if 1-([Months Remaining]/[Duration]) < 0 then 0 else 1-([Months Remaining]/[Duration])),
pctCpt.Type = Table.TransformColumnTypes(pctCPt.Add,{{"Percentage Complete", Percentage.Type}}),
pctCpt.Roundoff = Table.TransformColumns(pctCpt.Type,{{"Percentage Complete", each Number.Round(_, 2), Percentage.Type}}),
#"Filtered Rows1" = Table.SelectRows(pctCpt.Roundoff, each [Months Remaining] > 0),
monthsLeft.List = Table.TransformColumns(#"Filtered Rows1", {"Months Remaining", each List.Numbers(_,_,0), type list}),
monthsLeft.ListExpand = Table.ExpandListColumn(monthsLeft.List, "Months Remaining"),
/* my bit added here ------------------------------- */
countColumnAdd = Table.AddColumn(monthsLeft.ListExpand, "Instance", each 1),
TableType = Value.Type(Table.AddColumn(countColumnAdd, "Running Count", each null, type number)),
fnGrouping = (MyTable as table) as table =>
let
Source = Table.Buffer(MyTable),
TableType = Value.Type(Table.AddColumn(Source, "Running Count", each null, type number)),
Cumulative = List.Skip(List.Accumulate(Source[Instance],{0},(cumulative,instance) => cumulative & {List.Last(cumulative) + instance})),
RunningCount = Table.FromColumns(Table.ToColumns(Source)&{Cumulative},TableType)
in
RunningCount,
rowsGrouped = Table.Group(countColumnAdd, {"Project Name"}, {{"AllData", fnGrouping, TableType}}),
groupsExpanded = Table.ExpandTableColumn(rowsGrouped, "AllData", {"Budget ID", "Project Nam", "Renamed", "Division/Department", "Project Manager", "Spending Geometry", "Status", "Est. Start Date", "Est. End Date", "Running Count"},{"Budget ID", "Project Nam", "Renamed", "Division/Department", "Project Manager", "Spending Geometry", "Status", "Est. Start Date", "Est. End Date", "Running Count"}
),
projectOrder.Sort = Table.Sort(groupsExpanded,{{"Project Name", Order.Ascending}})
in
projectOrder.Sort