Forum Discussion
Calculate difference between values in same column
- Anonymous2 years ago
I found the solution!
thought I'd share it with you, sice you've all been so helpfull.
Gereden km's tussen tankbeurten =
VAR CurrentVehicle = 'F: Tankgegevens'[Voertuignummer]
VAR CurrentDate = 'F: Tankgegevens'[Datum]
VAR CurrentKM = 'F: Tankgegevens'[KM-stand]VAR PreviousKM =
CALCULATE(
MAX('F: Tankgegevens'[KM-stand]),
FILTER(
'F: Tankgegevens',
'F: Tankgegevens'[Voertuignummer] = CurrentVehicle &&
'F: Tankgegevens'[Datum] < CurrentDate
)
)RETURN
IF(
NOT ISBLANK(PreviousKM),
CurrentKM - PreviousKM,
BLANK()
)
Hello Anonymous can you provide an example of your expected result.
| vehicle | date | quantity | mileage | diff in mileage | consumption | |
| 8374 | 28/09/2023 | 46,6 | 99212 | |||
| 8374 | 2/10/2023 | 29,06 | 99605 | 393 | 13,52374398 | |
| 8374 | 5/10/2023 | 30,09 | 99970 | 365 | 12,13027584 | |
first, I need the difference in mileage (per vehicle number!/date), so i can make a measure for the consumption (difference in mileage/quantity).
Is that enough info?
- miTutorials2 years agoSuper User
Please try the below measure, change the table name accordingly.
Difference in Mileage = VAR Off_ = CALCULATE(SUM('Table (2)'[mileage]),OFFSET(-1,ALLSELECTED('Table (2)'[date ]),ORDERBY('Table (2)'[date ]))) VAR Cur_ = CALCULATE(SUM('Table (2)'[mileage]),OFFSET(0,ALLSELECTED('Table (2)'[date ]),ORDERBY('Table (2)'[date ]))) Return IF(ISBLANK(Off_),BLANK(), Cur_ - Off_)A detailed video on this functions are on my channel, do check it out.
New Dax Functions in PowerBI | Index, Offset & Window | MiTutorials (youtube.com)
Regards
Ismail
- Anonymous2 years agoNot applicable
The measure doesn't give any errors, but it doesn't work.