Forum Discussion
Ryan0096
2 years agoFrequent Visitor
Need date differences by status change when status changes
We have work IDs that can go through status 0-10 and it is not uncommon for it to go forward and backwards. Trying to get the date changes between the sequences so min when it ws in status x and mi...
- 2 years ago
Your updated example makes more sense, except for the missing Datediff entry on row 4 which I assume is a typo. Try this:
let Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Status", Int64.Type}, {"Date", type date}}), //Note use of GroupKind.Local //Add a column showing the minimum date for each status group #"Grouped Rows" = Table.Group(#"Changed Type", {"ID", "Status"}, { {"all", (t)=> Table.AddColumn(t, "Min Date", each List.Min(t[Date])), type table [ID=nullable number, Status=nullable number, Date=nullable date, Min Date = nullable date]} }, GroupKind.Local), #"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"Date", "Min Date"}), //Shift the min date column for easier comparisons #"Shifted Min Date" = Table.FromColumns( Table.ToColumns(#"Expanded all") & {{null} & List.RemoveLastN(#"Expanded all"[Min Date])}, type table [ID=nullable number, Status=nullable number, Date=nullable date, Min Date = nullable date, Shifted Min = nullable date] ), //Add the Datediff column at the change in status position #"Add Need"= Table.AddColumn(#"Shifted Min Date", "Datediff on Change", each if Duration.Days([Min Date] - [Shifted Min])= 0 then null else Duration.Days([Min Date] - [Shifted Min]), Int64.Type), #"Removed Columns" = Table.RemoveColumns(#"Add Need",{"Shifted Min", "ID", "Min Date"}) in #"Removed Columns"
ronrsnfld
Super User
2 years agoI don't understand your entries in Need for row 11 to row 14
11. No change in status c/w 10 but Need = 1
12. Status changeds from 2 to 1 but Need = null
13. No change in status but Need = 2
14. Status change, but min date of previous status is 2 days earlier, Need = 1
Ryan0096
2 years agoFrequent Visitor
Another way to put it, I need the date difference from the first date the status changes vs the first date of the new status change per ID and in sequence for when the status will go forward and backward. In row 11,14 and 15 it only stayed in the prior status for 1 day. In row 8 the status changed that day to status 1 but it was in status 2 for 4 days.