Forum Discussion
Anonymous
2 years agoNot applicable
Sort by date and provide unique identifier
Hi, My table consists of a range of activities with a huge range of start and end dates. I have written this piece of code to determine which activities are occurring in the 6 weeks (It seems to ...
- 2 years ago
Hi Anonymous, try this:
Result:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckwuySzLLKlUyM9LVdJRstA31jcyMDIBMg1NEWwzhfLU1GylWB0kDSXl+SBVBhBVRhC2CYydX1qCpjyjKBVkgyHCVGP8FqTllxaBNJgj6TDA1BILAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Activity = _t, #"Start date" = _t, #"End date" = _t, #"Within 6 weeks" = _t]), #"v1_Changed Type" = Table.TransformColumnTypes(Source,{{"Start date", type date}, {"End date", type date}}, "sk-SK"), #"v1_Added Index" = Table.AddIndexColumn(#"v1_Changed Type", "Index", 0, 1, Int64.Type), #"v1_Grouped Rows" = Table.Group(#"v1_Added Index", {"Within 6 weeks"}, {{"All", each Table.AddIndexColumn(Table.Sort(_, {"Start date", Order.Ascending}), "Unique ID", 1, 1, Int64.Type) , type table}}), v1_CombinedTables = Table.Combine(#"v1_Grouped Rows"[All]), v1_ReplaceValues = Table.ReplaceValue( v1_CombinedTables, each [Within 6 weeks], null, (x,y,z)=> if y = "out" then null else x, {"Unique ID"} ), #"v1_Sorted Rows" = Table.Sort(v1_ReplaceValues,{{"Index", Order.Ascending}}), #"v1_Removed Columns" = Table.RemoveColumns(#"v1_Sorted Rows",{"Index"}) in #"v1_Removed Columns"
dufoq3
2 years agoCommunity Champion
Hi Anonymous, try this:
Result:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckwuySzLLKlUyM9LVdJRstA31jcyMDIBMg1NEWwzhfLU1GylWB0kDSXl+SBVBhBVRhC2CYydX1qCpjyjKBVkgyHCVGP8FqTllxaBNJgj6TDA1BILAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Activity = _t, #"Start date" = _t, #"End date" = _t, #"Within 6 weeks" = _t]),
#"v1_Changed Type" = Table.TransformColumnTypes(Source,{{"Start date", type date}, {"End date", type date}}, "sk-SK"),
#"v1_Added Index" = Table.AddIndexColumn(#"v1_Changed Type", "Index", 0, 1, Int64.Type),
#"v1_Grouped Rows" = Table.Group(#"v1_Added Index", {"Within 6 weeks"}, {{"All", each Table.AddIndexColumn(Table.Sort(_, {"Start date", Order.Ascending}), "Unique ID", 1, 1, Int64.Type) , type table}}),
v1_CombinedTables = Table.Combine(#"v1_Grouped Rows"[All]),
v1_ReplaceValues = Table.ReplaceValue( v1_CombinedTables,
each [Within 6 weeks],
null,
(x,y,z)=> if y = "out" then null else x,
{"Unique ID"} ),
#"v1_Sorted Rows" = Table.Sort(v1_ReplaceValues,{{"Index", Order.Ascending}}),
#"v1_Removed Columns" = Table.RemoveColumns(#"v1_Sorted Rows",{"Index"})
in
#"v1_Removed Columns"