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
3 years agoSuper User
Hi,
Can you try the below measure?
I am not sure about the performance, but I tried to fix the measure that can show the previous value.
Prev_value_Energy_consum1 =
VAR Index =
MAX ( FloatTable[TagIndex] )
VAR Prev_datetime =
MAXX (
FILTER (
ALL ( FloatTable ),
FloatTable[Date] = MAX ( FloatTable[Date] )
&& FloatTable[Time] < MAX ( FloatTable[Time] )
&& FloatTable[TagIndex] = Index
),
FloatTable[Time]
)
VAR Prev_date =
MAXX (
FILTER (
ALL ( FloatTable ),
FloatTable[Date] < MAX ( FloatTable[Date] )
&& FloatTable[TagIndex] = Index
),
FloatTable[Date]
)
VAR Prev_time =
MAXX (
FILTER (
ALL ( FloatTable ),
FloatTable[Date] = Prev_date
&& FloatTable[TagIndex] = Index
),
FloatTable[Time]
)
RETURN
SWITCH (
TRUE (),
NOT ISBLANK ( Prev_datetime ),
SUMX (
FILTER (
ALL ( FloatTable ),
FloatTable[Time] = Prev_datetime
&& FloatTable[Date] = MAX ( FloatTable[Date] )
&& FloatTable[TagIndex] = Index
),
FloatTable[Val]
),
CALCULATE (
SUMX (
FILTER (
ALL ( FloatTable ),
FloatTable[Time] = Prev_time
&& FloatTable[Date] = Prev_date
&& FloatTable[TagIndex] = Index
),
FloatTable[Val]
)
)
)
Anonymous
3 years agoNot applicable
Thanks for your measure Jihwan_Kim, but it is very slow...