Forum Discussion
Anonymous
5 years agoNot applicable
Delta values
Hi, How would I calculate Delta-values derived from a Date in combination with ID: Date ID Values Delta-values DD-MM-YYYY 12:00 1 88 DD-MM-YYYY 12:00 2 23 DD-MM-YYYY ...
- Anonymous5 years ago
Hi Anonymous ,
Here are the steps you can follow:
1. Increase the index through power query
2. Create calculcated column.
Delta-values = var _lastindex= CALCULATE(MAX('Table'[Index]),FILTER(ALL('Table'),[Metern]=EARLIER([Metern])&&[Index]<EARLIER([Index]))) var _lastdata= CALCULATE(SUM('Table'[Data]),FILTER('Table',[Index]=_lastindex)) return IF(_lastindex=BLANK(),BLANK(),[Data]-_lastdata)3. Result.
You can downloaded PBIX file from here.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
5 years agoNot applicable
Sorry - so Power Query it is..
Still need the a working code though!
Anonymous
5 years agoNot applicable
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hY9BCsAgDAS/UnK2mGytFL8i/v8btdCi1gUhOY3ZdXIWKHRXq7MZkmodcWJ1IcX9+dnxY+IhoeM28TjkB5L/cdD71g/6v9YPmh+H/GvkWPhj4Q/ur/Bq/nnF/XvO/Ec++/ec+fP+17/c", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Datetime = _t, ID = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Datetime", type datetime}, {"ID", Int64.Type}, {"Value", Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"ID", Order.Ascending}, {"Datetime", Order.Ascending}}),
#"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
#"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "Datetime", "ID", "Value"}),
#"Added Custom" = Table.AddColumn(#"Reordered Columns",
"ValueBefore",
each Table.SelectRows(
#"Reordered Columns",
(r) => r[ID] = [ID] and [Index] = r[Index] + 1)
),
#"Expanded ValueBefore" = Table.ExpandTableColumn(#"Added Custom", "ValueBefore", {"Value"}, {"Value.1"}),
#"Renamed Columns" = Table.RenameColumns(#"Expanded ValueBefore",{{"Value.1", "ValueBefore"}}),
#"Added Custom1" = Table.AddColumn(#"Renamed Columns", "Delta", each [Value] - [ValueBefore]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Value", "ValueBefore", "Index"})
in
#"Removed Columns"
Here's the M code. Paste it into the Advanced Editor in Power Query and you'll see step-by-step how this is done. Then use it accordingly.