Forum Discussion
Anonymous
3 years agoNot applicable
Getting Previous Row using DAX measure
Hello all, I need to get previous record based on DateTime column and grouped by TagIndex column I created this measure, Prev_value_Energy_consum = VAR Index = [Index] VAR Prev_date =...
- 3 years ago
Hi,
Thank you for your sharing.
Could you please try the below if it works?
Prev_value_Energy_consum = VAR Index = [Index] VAR Prev_datetime = MAXX ( FILTER ( ALLSELECTED ( FloatTable ), FloatTable[Date] = SELECTEDVALUE ( FloatTable[Date] ) && FloatTable[Time] < SELECTEDVALUE ( FloatTable[Time] ) ), FloatTable[Time] ) VAR Prev_date = MAXX ( FILTER ( ALLSELECTED ( FloatTable ), FloatTable[Date] < SELECTEDVALUE ( FloatTable[Date] ) ), FloatTable[Date] ) VAR Prev_time = MAXX ( FILTER ( ALLSELECTED ( FloatTable ), FloatTable[Date] = Prev_date ), FloatTable[Time] ) RETURN SWITCH ( TRUE (), NOT ISBLANK ( Prev_datetime ), CALCULATE ( SUMX ( FloatTable, VAR Index = FloatTable[TagIndex] RETURN FloatTable[Val] ), FILTER ( ALLSELECTED ( FloatTable ), FloatTable[Time] = Prev_datetime && FloatTable[Date] = SELECTEDVALUE ( FloatTable[Date] ) && FloatTable[TagIndex] = Index ) ), CALCULATE ( SUMX ( FloatTable, VAR Index = FloatTable[TagIndex] RETURN FloatTable[Val] ), FILTER ( ALLSELECTED ( FloatTable ), FloatTable[Time] = Prev_time && FloatTable[Date] = Prev_date && FloatTable[TagIndex] = Index ) ) )
Jihwan_Kim
Super User
3 years agoHi,
I am not sure if I understood your question correctly, but please try the below measure whether it suits your requirement.
Prev_value_Energy_consum =
VAR Prev_date =
MAXX (
FILTER (
ALLSELECTED ( FloatTable[Time] ),
FloatTable[Time] < SELECTEDVALUE ( FloatTable[Time] )
),
FloatTable[Time]
)
RETURN
CALCULATE (
SUMX ( FloatTable, FloatTable[Val] ),
FILTER ( ALLSELECTED ( FloatTable ), FloatTable[Time] = Prev_date )
)