Forum Discussion
Wickin
8 years agoFrequent Visitor
Calculate difference between two rows by using Index column
Hi al, I know this question has been asked before, but I tried them all and wasn't able to compete. Sorry! I've got the below table (4 colums) within Power BI (just created a table in Excel t...
- 8 years ago
try this
Column = VAR Index = 'Table'[Index] VAR Reference = 'Table'[Reference] VAR PrevKilometers = CALCULATE ( FIRSTNONBLANK ( 'Table'[Kilometers], TRUE () ), FILTER ( 'Table', 'Table'[Index] = Index - 1 && 'Table'[Reference] = Reference ) ) RETURN IF ( ISBLANK ( PrevKilometers ), BLANK (), 'Table'[Kilometers] - PrevKilometers )
Stachu
8 years agoCommunity Champion
try this
Column =
VAR Index = 'Table'[Index]
VAR Reference = 'Table'[Reference]
VAR PrevKilometers =
CALCULATE (
FIRSTNONBLANK ( 'Table'[Kilometers], TRUE () ),
FILTER ( 'Table', 'Table'[Index] = Index - 1 && 'Table'[Reference] = Reference )
)
RETURN
IF (
ISBLANK ( PrevKilometers ),
BLANK (),
'Table'[Kilometers] - PrevKilometers
)Anonymous
6 years agoNot applicable
How can I adjust your formula to include data also as a criteria ?
i.e.,compare the values between current timestamp and previous time stamp,say 17-08-2019,10:25 P.M and 17-08-2019,10:30 P.M.
I have an ID Field and the glucose values,I should be capable of comparing the glucose_value,every now and then to indicate the episodes or spike in glucose level.
Thanks
- Stachu6 years agoCommunity Champion
the ID can be the same for multiple dates?
if yes then the difference in glucose for a given ID should be something like this:Column = VAR __ID = 'Table'[ID] VAR __DateTime = 'Table'[DateTime] VAR __PreviousDateTime = CALCULATE ( MAX ( 'Table'[DateTime] ), FILTER ( 'Table', 'Table'[ID] = __ID && 'Table'[DateTime] < __DateTime) ) VAR __PreviousGlucose = CALCULATE ( MAX ( 'Table'[Glucose] ), FILTER ( 'Table', 'Table'[ID] = __ID && 'Table'[DateTime] = __PreviousDateTime) ) RETURN IF ( ISBLANK ( __PreviousDateTime ), BLANK (), 'Table'[Glucose] - __PreviousGlucose )