Forum Discussion
Calculate days between dates in rows
- Anonymous9 years ago
Hi,
If you wish to create two new columns for days from previous row and traveled distance you can calculate them like this:
First the column for days from previous date=
var curdate='Table1'[Date]
return
CALCULATE(
DATEDIFF(
MAX('Table1'[Date]);
curdate;
DAY
);
FILTER('Table1';
'Table1'[Date]<curdate
)
)Then you create next column for Distance from previous date=
var curdist=[ODO]
return
IF(
not ISBLANK([Days from previous]);
CALCULATE(
curdist-MAX('Table1'[ODO]);
FILTER(
'Table1';
Table1[ODO]<curdist
)
)
)Make sure you substitute the table and column names in the code to make this work in your specific case.
Br,
Magnus
Hi,
If you wish to create two new columns for days from previous row and traveled distance you can calculate them like this:
First the column for days from previous date=
var curdate='Table1'[Date]
return
CALCULATE(
DATEDIFF(
MAX('Table1'[Date]);
curdate;
DAY
);
FILTER('Table1';
'Table1'[Date]<curdate
)
)
Then you create next column for Distance from previous date=
var curdist=[ODO]
return
IF(
not ISBLANK([Days from previous]);
CALCULATE(
curdist-MAX('Table1'[ODO]);
FILTER(
'Table1';
Table1[ODO]<curdist
)
)
)
Make sure you substitute the table and column names in the code to make this work in your specific case.
Br,
Magnus
Oh my friend! That's a solution. Many thanks to you. I added a new columns 'Distance per day' and 'Consumption per 100km' based on Days and Distance columns ... and some visualisations. Excelent support from you!!!