Forum Discussion
Adding rows by date
- 1 year ago
Hi Jodallen123 I suppose you are asking how to create the end date column right
Create a custom column for the "end date" of each status by shifting the "Created_date" column of the next row upwards:
Go to the "Add Column" tab -> "Custom Column" -> Formula
End_Date = Table.AddColumn(#"Previous Step", "End_Date", each Table.RowAfter([Created_dat
e]))
- 1 year ago
Because you mentioned you have multiple order numbers, I would start by
- Group by Order Number
- Custom aggregation:
- Add Index Column
- Add column with a list of the requisite rows
- Then expand everything.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAyNDEyV9JR8szLLMlMzFEILkksKS0GCgSXpBYoGAIZBkBsZGBkrGtgpGsEEYjVQdIJVwhmGKHrMAZxsOgwgjGMUXSANAE55lh0GMMYJug6QDKGWHSYwBimKDpMdA0tgBwTM6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [orderNumber = _t, status_changed_from = _t, status_changed_to = _t, current_status = _t, Created_date = _t, days_with_status = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"orderNumber", Int64.Type}, {"status_changed_from", type text}, {"status_changed_to", type text}, {"current_status", Int64.Type}, {"Created_date", type date}, {"days_with_status", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"orderNumber"}, { {"New Table",(t)=> [a=Table.AddIndexColumn(t,"Index",0,1,Int64.Type), b=Table.AddColumn(a,"Created Dates", each try List.Dates([Created_date],a[days_with_status]{[Index]+1}, #duration(1,0,0,0)) otherwise {[Created_date]}), c=Table.RemoveColumns(b,{"Index"})] [c], type table[orderNumber=Int64.Type, status_changed_from=text, status_changed_to=text, current_status=Int64.Type, Created_date=date, days_with_status=Int64.Type, Created Dates={date}] }}), #"Expanded New Table" = Table.ExpandTableColumn(#"Grouped Rows", "New Table", {"status_changed_from", "status_changed_to", "current_status", "Created_date", "days_with_status", "Created Dates"}), #"Expanded Created Dates" = Table.ExpandListColumn(#"Expanded New Table", "Created Dates"), #"Removed Columns" = Table.RemoveColumns(#"Expanded Created Dates",{"Created_date"}), #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns", {"orderNumber", "status_changed_from", "status_changed_to", "current_status", "Created Dates", "days_with_status"}) in #"Reordered Columns" - 1 year ago
Hi Jodallen123
to solve this problem, you can use the following code in the advance editor
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAyNDEyV9JR8szLLMlMzFEILkksKS0GCgSXpBYoGAIZBkBsZGBkrGtgpGsEEYjVQdIJVwhmGKHrMAZxsOgwgjGMUXSANAE55lh0GMMYJug6QDKGWHSYwBimKDpMdA0tgBwTM6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [orderNumber = _t, status_changed_from = _t, status_changed_to = _t, current_status = _t, Created_date = _t, days_with_status = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"orderNumber", Int64.Type}, {"status_changed_from", type text}, {"status_changed_to", type text}, {"current_status", Int64.Type}, {"Created_date", type date}, {"days_with_status", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [a=List.RemoveFirstN(#"Changed Type"[Created_date], (x)=>x<[Created_date]),b=try List.Dates(a{0},Number.From(a{1}-a{0}),Duration.From(1)) otherwise a][b]), #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom") in #"Expanded Custom"
Hi Jodallen123 Could you try this please
Add End Date Column: Create a column with the next row's Created_date as End_Date. Fill missing values for the last row.
Generate Date Range: Add a column to generate dates between Created_date and End_Date - 1 :
List.Dates([Created_date], Duration.Days([End_Date] - [Created_date]), #duration(1, 0, 0, 0))Expand Dates: Expand the date list into new rows.
Add Status Columns: Retain original columns for each expanded row.
If this post helped please do give a kudos and accept this as a solution
Thanks In Advance
- Jodallen1231 year agoHelper I
Hi,
Thanks alot!
I thought about adding an end_date column as well, if I had that I think I can manage the rest, I am however unsure how that can be done. Have you or anyone else here done something similar and have any input?
- Akash_Varuna1 year agoSuper User
Hi Jodallen123 I suppose you are asking how to create the end date column right
Create a custom column for the "end date" of each status by shifting the "Created_date" column of the next row upwards:
Go to the "Add Column" tab -> "Custom Column" -> Formula
End_Date = Table.AddColumn(#"Previous Step", "End_Date", each Table.RowAfter([Created_dat
e]))