Hi Michelle,
Sure I think we can work off the Max Process and keep all the data, give this a go.
I’m returning “Done” for skipped steps and “Days in Status” should return null
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjBwVNJRMgRhE93c1EylWB2YoBEIG6AJGgMxEtcElWuK4DpBjTXXzSrNQxIDmWqBJgYy1BJNDGSyoQGaIMT8WAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Project = _t, Process = _t, #"End Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Process", Int64.Type}, {"End Date", type date}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Project"}, {{"AllRows", each _, type table [Project=nullable text, Process=nullable number, End Date=nullable date]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each
let
myTable = [AllRows],
SortRows = Table.Sort(myTable,{{"Process", Order.Ascending}}),
AddIndex = Table.AddIndexColumn( SortRows, "Index", 0, 1 ),
MaxProcess = List.Max( Table.SelectRows(SortRows, each [End Date] <>null )[Process] ),
ListEndDates = Table.FillDown( AddIndex[[End Date]], {"End Date"} )[End Date],
AddStatus = Table.AddColumn(AddIndex, "Status", each if [Process] <= MaxProcess then "Done" else if AddIndex{[Index]-1}[End Date] is date then "In Progress" else null, type text),
AddDays = Table.AddColumn(AddStatus, "Days in Status", each if [Index] =0 or ( [Status] = "Done" and [End Date] =null ) then null else if [Status] = "Done" or [Status] = "In Progress" then
List.Count(
List.Select(
//List.Difference(
List.Dates(ListEndDates{[Index]-1}, Number.From( (if [End Date]=null then Date.From(DateTime.FixedLocalNow()) else [End Date]) - ListEndDates{[Index]-1} ) +1, Duration.From(1)),
//List.Transform(HolidayList, Date.From )),
each Date.DayOfWeek(_, 1) < 5 )
) else null, type number )
in
AddDays, type table [Project=nullable text, Process=nullable number, End Date=nullable date, Status = text, Days in Status = number])[[Custom]],
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Project", "Process", "End Date", "Status", "Days in Status"}, {"Project", "Process", "End Date", "Status", "Days in Status"})
in
#"Expanded Custom"
I hope this is helpful.