Forum Discussion

tester's avatar
tester
Frequent Visitor
8 years ago
Solved

Delta Calculation per Time Period for Group Values

I've seen a hundred posts on this but no real solution. 

 

My data:

 

GroupDateValue
a1/13/2015897
a1/9/2015200
a1/1/2015647
b1/13/20152
b1/9/2015978
b1/1/2015655
c1/13/201561
c1/9/201536
c1/1/2015959


What I need: a delta calculation that subtracts the difference of each value from last week, for each group. Ergo:

 

GroupDateValueDelta
a1/13/2015897697
a1/9/2015200-447
a1/1/20156470
b1/13/20152-976
b1/9/2015978323
b1/1/20156550
c1/13/20156125
c1/9/201536-923
c1/1/20159590

 

Note where the delta is 0.

 

This is easily achieved in R:

 

dataset %>%
group_by(Group) %>%
mutate(Delta = Value - lag(Value, order_by=Date))

Unfortunately there's no real enterprise support for R in PBI Service. So how do we do this with M/DAX?