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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Mileage Calculation

Hi Community,

 

I have the below two datasets

 

Dataset 1 

Vehicle RegStart DateEnd DateDistance (Miles)
12301/01/202101/01/202110
12302/01/202102/01/202120
12302/01/202102/01/202130

 

Dataset 2 

Vehicle RegDaily Commute (Miles)
1233
1242
1254

 

I need to create a calulcation showing me total amount of mileage covered per vehicle reg in dataset 1 - vehicle reg's daily commute for each day they have travelled.

 

Any ideas on how this can be achieved?

 

Many thanks,

 

Elliot 

1 ACCEPTED SOLUTION

See if this works.

The model

model.JPG

The measures 

 

Mileage =
SUM ( 'Dataset 1'[Distance (Miles)] )
Daily Commute = SUM('Dataset 2'[Daily Commute (Miles)])
RegDaily Commute =
SUMX (
    ADDCOLUMNS (
        SUMMARIZE ( 'Dataset 1', 'Dataset 1'[Start Date], 'Dataset 2'[Vehicle Reg] ),
        "DC", [Daily Commute]
    ),
    [DC]
)
Net Mileage =
[Mileage] - [RegDaily Commute]

 

to get..

Result.JPG

 

I've attached the sample PBIX file

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

9 REPLIES 9
PaulDBrown
Community Champion
Community Champion

you clarify the calcualtion? Is it just the daily mileage minus the daily reg value?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi,

 

Yes, the calulcation is as follows

 

Sum of Distance Miles (dataset1) - commute miles (dataset2)        

 

Please note the commute miles (dataset2) will need to be minused for every active day in dataset 1.

 

Hope this makes sense.

 

Elliot 

Sorry, what do you mean by "will need to be minused for every active day in dataset 1"?

Also, will there be unique Vehicle reg values in Dataset 2 or will there be duplicates?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Example below

 

Dataset 1 

Vehicle RegStart DateEnd DateDistance (Miles)
12301/01/202101/01/202110
12301/01/202101/01/202115
12302/01/202102/01/202120
12302/01/202102/01/202130

 

Dataset 2 

Vehicle RegDaily Commute (Miles)
1233
1242
1254

 

Sum would be as follows

 

Sum of Distance Miles in dataset 1 = 75

75 - Daily Commute miles for every day mentioned in dataset 1 = 69

 

For every vehicle reg in dataset 1 there will be a the same vehicle reg in dataset 2 along with its daily commute mileage.

See if this works.

The model

model.JPG

The measures 

 

Mileage =
SUM ( 'Dataset 1'[Distance (Miles)] )
Daily Commute = SUM('Dataset 2'[Daily Commute (Miles)])
RegDaily Commute =
SUMX (
    ADDCOLUMNS (
        SUMMARIZE ( 'Dataset 1', 'Dataset 1'[Start Date], 'Dataset 2'[Vehicle Reg] ),
        "DC", [Daily Commute]
    ),
    [DC]
)
Net Mileage =
[Mileage] - [RegDaily Commute]

 

to get..

Result.JPG

 

I've attached the sample PBIX file

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi Paul,

 

After putting the formula to the test with real data I am getting a strange result.

 

The formula is working correct as seen in the below table screenshot (some vehicles will not have daily commute miles allocated) but for some reason the sum of all RegDailyCommute is alot higher than all of the values added together.

 

Any ideas?Capture.PNG

@Anonymous 

 

I'm not sure what's going on at your end. I've just added a new reg with no daily commute and the measures work.

Result no DC.JPG

 Can you post the code you are using for the [RegDaily commute] measure?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi,

 

I have changed the relationship settings to 'both ways' this seems to have solved it!

 

Many thanks,

 

Elliot 

Anonymous
Not applicable

Thats spot on!

 

Thank you for taking the time in your day to help me!

 

Elliot 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.