This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Hi,
I have a table in Excel (to be imported into Power Bi) which has dates down one side (running from January 2010 to way into the future)
My columns are vehicles A, B and C (but over 100 of them) and the date within the spreadsheet is cumulative miles
I'm looking at creating a new table which will show me the daily miles instead so A would show 232 which is the difference between 15th and 16th
Does anyone know of a way to do this please?
Solved! Go to Solution.
Firstly I would recommend you Unpivot the Vehicle columns.
You can then create a calculated column to get the daily mileage for each vehicle using:
Daily Mileage =
VAR PrevDate =
CALCULATE (
SUM ( 'DataTable'[Mileage] ),
FILTER (
'DataTable',
'DataTable'[Vehicle] = EARLIER ( 'DataTable'[Vehicle] )
&& 'DataTable'[Date]
= EARLIER ( 'DataTable'[Date] ) - 1
)
)
VAR CurrDate =
CALCULATE (
SUM ( 'DataTable'[Mileage] ),
FILTER (
'DataTable',
'DataTable'[Vehicle] = EARLIER ( 'DataTable'[Vehicle] )
&& 'DataTable'[Date] = EARLIER ( 'DataTable'[Date] )
)
)
RETURN
CurrDate - PrevDate
To get:
If you want the "Daily Mileage" for the first (minimum) date to be blank, use:
Daily Mileage =
VAR MinDate =
MIN ( 'DataTable'[Date] )
VAR PrevDate =
CALCULATE (
SUM ( 'DataTable'[Mileage] ),
FILTER (
'DataTable',
'DataTable'[Vehicle] = EARLIER ( 'DataTable'[Vehicle] )
&& 'DataTable'[Date]
= EARLIER ( 'DataTable'[Date] ) - 1
)
)
VAR CurrDate =
CALCULATE (
SUM ( 'DataTable'[Mileage] ),
FILTER (
'DataTable',
'DataTable'[Vehicle] = EARLIER ( 'DataTable'[Vehicle] )
&& 'DataTable'[Date] = EARLIER ( 'DataTable'[Date] )
)
)
RETURN
IF ( 'DataTable'[Date] = MinDate, BLANK (), CurrDate - PrevDate )
I've attached the sample PBIX file
Proud to be a Super User!
Paul on Linkedin.
Firstly I would recommend you Unpivot the Vehicle columns.
You can then create a calculated column to get the daily mileage for each vehicle using:
Daily Mileage =
VAR PrevDate =
CALCULATE (
SUM ( 'DataTable'[Mileage] ),
FILTER (
'DataTable',
'DataTable'[Vehicle] = EARLIER ( 'DataTable'[Vehicle] )
&& 'DataTable'[Date]
= EARLIER ( 'DataTable'[Date] ) - 1
)
)
VAR CurrDate =
CALCULATE (
SUM ( 'DataTable'[Mileage] ),
FILTER (
'DataTable',
'DataTable'[Vehicle] = EARLIER ( 'DataTable'[Vehicle] )
&& 'DataTable'[Date] = EARLIER ( 'DataTable'[Date] )
)
)
RETURN
CurrDate - PrevDate
To get:
If you want the "Daily Mileage" for the first (minimum) date to be blank, use:
Daily Mileage =
VAR MinDate =
MIN ( 'DataTable'[Date] )
VAR PrevDate =
CALCULATE (
SUM ( 'DataTable'[Mileage] ),
FILTER (
'DataTable',
'DataTable'[Vehicle] = EARLIER ( 'DataTable'[Vehicle] )
&& 'DataTable'[Date]
= EARLIER ( 'DataTable'[Date] ) - 1
)
)
VAR CurrDate =
CALCULATE (
SUM ( 'DataTable'[Mileage] ),
FILTER (
'DataTable',
'DataTable'[Vehicle] = EARLIER ( 'DataTable'[Vehicle] )
&& 'DataTable'[Date] = EARLIER ( 'DataTable'[Date] )
)
)
RETURN
IF ( 'DataTable'[Date] = MinDate, BLANK (), CurrDate - PrevDate )
I've attached the sample PBIX file
Proud to be a Super User!
Paul on Linkedin.
does exactly as I needed - thanks for this 👍
please provide sample data and expected result for the issue
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 35 | |
| 32 | |
| 26 | |
| 21 | |
| 18 |
| User | Count |
|---|---|
| 68 | |
| 37 | |
| 32 | |
| 25 | |
| 23 |