Forum Discussion
Running change/delta per category
- Anonymous4 years ago
Hi rashidanwar ,
You could understand by looking at his every step.
1.This is what the dataset looked like initially.
2.Here he creates a function that will be used later.
3.In this step, he groups the original table by call_id.
4.In this step, he adds a custom column that uses the previously created function.
5.Expand the fxProcessDelta column.
6.Remove the Temp column.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc5LDoAgDATQqxjWJkwHAe3Ozy0I97+GjZIQcdHVvMy0FCd0s9vtEDyTJ8hJoCJqSZ0bOAYQVTZF7uBsIL8A8jSsLwj/CUCxqaCDcSIpDeQOxglav7I1LBZeX2AP2BvRQL0B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [call_id = _t, #"type" = _t, time = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"call_id", Int64.Type}, {"type", type text}, {"time", type datetime}}),
// Function Start
fxProcessDelta=(Tbl)=>
let
#"Added Index" = Table.AddIndexColumn(Tbl, "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Delta", each if [Index]=0 then null else [time]-#"Added Index"[time]{[Index]-1})
in
#"Added Custom",
// Function End
#"Grouped Rows" = Table.Group(#"Changed Type", {"call_id"}, {{"Temp", each _, type table [call_id=nullable number, type=nullable text, time=nullable datetime]}}),
#"Invoked Custom Function" = Table.AddColumn(#"Grouped Rows", "fxProcessDelta", each fxProcessDelta([Temp])),
#"Expanded fxProcessDelta" = Table.ExpandTableColumn(#"Invoked Custom Function", "fxProcessDelta", {"type", "time", "Delta"}, {"type", "time", "Delta"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded fxProcessDelta",{"Temp"})
in
#"Removed Columns"
Thank you so much Vijay_A_Verma for your time and support. Can we have a more clean solution without having too much code? All I know that beauty of power query is to do the data transformation with out much coding.
- Anonymous4 years agoNot applicable
Hi rashidanwar ,
You could understand by looking at his every step.
1.This is what the dataset looked like initially.
2.Here he creates a function that will be used later.
3.In this step, he groups the original table by call_id.
4.In this step, he adds a custom column that uses the previously created function.
5.Expand the fxProcessDelta column.
6.Remove the Temp column.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.