Forum Discussion
ddijstelbloem
4 years agoFrequent Visitor
Fill missing dates with previous value
Hi, Already search for a solution but can not find one which actually fits my request. So please find my question below. I have a date table and a table with inventory, (related by date) I need to h...
- 4 years ago
Hi ddijstelbloem ,
Try this:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc5BDsAgCATAv3CWBLZq7VuI//9GpXiqcNpksoAZAaxgKBXqAvFZsXaaxUhvVoYAP62hT6rYysgQH7YD/QEd0ZRc90/tuOrxisU6cl3d+QI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [MutationDate = _t, Partcode = _t, CumInvQty = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"MutationDate", type text}, {"Partcode", Int64.Type}, {"CumInvQty", Int64.Type}}), #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"MutationDate", type date}}, "en-GB"), #"Sorted Rows" = Table.Sort(#"Changed Type with Locale",{{"Partcode", Order.Ascending}, {"MutationDate", Order.Ascending}}), #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1, Int64.Type), #"Added Custom" = Table.AddColumn(#"Added Index", "FilledMutationDate", each let EndDate_ = let NextPartcode_ = try #"Added Index"[Partcode]{ [Index] + 1 } otherwise null, NextDate_= try #"Added Index" [MutationDate] { [Index] + 1 } otherwise null in if [Partcode]=NextPartcode_ then Number.From(NextDate_)-1 else Number.From([MutationDate]) in {Number.From([MutationDate])..EndDate_}), #"Expanded FilledMutationDate" = Table.ExpandListColumn(#"Added Custom", "FilledMutationDate"), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded FilledMutationDate",{{"FilledMutationDate", type date}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"MutationDate", "Index"}), #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"FilledMutationDate", "Partcode", "CumInvQty"}) in #"Reordered Columns"Source Table:
Result Table:
...
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Icey
4 years agoCommunity Support
Hi ddijstelbloem ,
Try this:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc5BDsAgCATAv3CWBLZq7VuI//9GpXiqcNpksoAZAaxgKBXqAvFZsXaaxUhvVoYAP62hT6rYysgQH7YD/QEd0ZRc90/tuOrxisU6cl3d+QI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [MutationDate = _t, Partcode = _t, CumInvQty = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"MutationDate", type text}, {"Partcode", Int64.Type}, {"CumInvQty", Int64.Type}}),
#"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"MutationDate", type date}}, "en-GB"),
#"Sorted Rows" = Table.Sort(#"Changed Type with Locale",{{"Partcode", Order.Ascending}, {"MutationDate", Order.Ascending}}),
#"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "FilledMutationDate", each let EndDate_ =
let NextPartcode_ = try #"Added Index"[Partcode]{ [Index] + 1 } otherwise null, NextDate_= try #"Added Index" [MutationDate] { [Index] + 1 } otherwise null
in if [Partcode]=NextPartcode_ then Number.From(NextDate_)-1 else Number.From([MutationDate])
in {Number.From([MutationDate])..EndDate_}),
#"Expanded FilledMutationDate" = Table.ExpandListColumn(#"Added Custom", "FilledMutationDate"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded FilledMutationDate",{{"FilledMutationDate", type date}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"MutationDate", "Index"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"FilledMutationDate", "Partcode", "CumInvQty"})
in
#"Reordered Columns"
Source Table:
Result Table:
...
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ddijstelbloem
4 years agoFrequent Visitor
I have replaced the source but now I keep getting an error. Can you see what is wrong?
- Icey4 years agoCommunity Support