Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
gingerclaire
Helper III
Helper III

Calculating monthly mileage - dealing with outliers and empty values

I have a mileage spreadsheet and in it I am using the following measure to work out how much mileage they have done in each month:

 

Mileage since last month = 'Car report data'[Current mileage:]-'Car report data'[Prev Reading]
 
To get Prev Reading I am using the following calculated column:
 
Prev Reading =
MAXX(
TOPN(
1,
FILTER(
'Car report data',
'Car report data'[Car reg] = EARLIER( 'Car report data'[Car reg] )
&& 'Car report data'[Start time] < EARLIER( 'Car report data'[Start time] )
),
'Car report data'[Start time]
),
'Car report data'[Current mileage:]
)
 
The problem is that when there is no previous reading, then this throws out a negative number.
 
Would I better saying if there is no previous reading it should = 0? How would i do this?
 
The issue is that some of the drivers have had several different cars, but I want to see their miles driven each month by driver (regardless of car) so that I can then forecast their mileage needs (to ensure their contract allows for this).
 
Any help gratefully received.
3 REPLIES 3
daXtreme
Solution Sage
Solution Sage

Instead of trying to twist and turn your data to suit your complex calculations, transform the data to make your calculations easy. This is the first part of data modeling art. So, if the granularity of your calendar is 'day', just make sure that your fact table does not store cumulative mileages but mileages per day. Then everything will become very easy. Obviously, if the calendar granularity should be 'month,' store mileages per month.

Thank you - the data is actually from an MS Form where the drivers enter their current mileage - so I need to convert it somehow.

Anonymous
Not applicable

Hi @gingerclaire ,

In order to provide you a suitable solution, could you please provide some sample data in the table "Car report data" (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

How to upload PBI in Community

Best Regards 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.