web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Calculating Total Cost...
Power Apps
Answered

Calculating Total Cost Based on Miles and Transport Type in PowerApps

(0) ShareShare
ReportReport
Posted on by 70

Is it possible to do this:

I have a dropdown box for 3 types of transport; private car, company petrol and company diesel.

All these have different values/mile; Private car is £0.45/mile, Diesel is £0.16/mile, Petrol is £0.17/mile

And then I have a textbox where people will put in how many miles they've done. 

These need to get multiplied and calculated into a total in £. 

Is this possible to do or would it be extremely difficult? 

Hope it makes sense.

Thank You 🙂

 

Categories:
I have the same question (0)
  • CarlosFigueira Profile Picture
    on at

    If you set your dropdown Items property to something like this:

     

     

    [
     { Name: "Private car", ValuePerMile: 0.45 },
     { Name: "Diesel", ValuePerMile: 0.16 },
     { Name: "Petrol", ValuePerMile: 0.17 }
    ]

     

     

    Then you can calculate the total cost using an expression like this one below (assuming the transport type dropdown is called 'drpTransportType' and the text input for the number of miles is called txtNumberOfMiles):

     

     

    drpTransportType.Selected.ValuePerMile * Value(txtNumberOfMiles.Text)

     

     

    Hope this helps!

     

    A few notes:

    - If you are using the modern text input control, you would use 'txtNumberOfMiles.Value' instead of '.Text'

    - Normally the value per mile would be stored in a data source such as Dataverse or SharePoint, so that if the values need to be changed the app won't need to be updated

  • Cseni Profile Picture
    70 on at

    Thank You the first part worked but the second im still figuring out, do you think it will be easier for it to just go straight to sharepoint then? Not sure how I'd do that. Also I've realised that in the "nights away " textbox, it needs to be £10/night so that complicates it further. 😕

  • CarlosFigueira Profile Picture
    on at

    For the nights away text box you can use that in the same expression to calculate the total value:

    drpTransportType.Selected.ValuePerMile * Value(txtNumberOfMiles.Text) + 10 * Value(txtNightsAway.Text)

    To store the values in SharePoint, you can have a list (let's call it 'ReimbursementCostPerMile') with two columns: Name (text) and ValuePerMile (number), and populate it with the values you need. Then you would set the Items property of your dropdown to that list, and it would work like with the "hardcoded" values.

  • Cseni Profile Picture
    70 on at

    Hi, 

    Please could you help. I think I've done something wrong. So for the dropdown I used a SharePoint list and when I add the code underneath it comes up with the error message below and the dropdown box doesn't say the types of cars anymore its just blank. I'm not sure what I've done wrong. 

    Thank you! 🙂

     Transport code.PNG

    Issue.PNG

    Transport issue.PNG

  • Verified answer
    CarlosFigueira Profile Picture
    on at

    If you have a SP list with the Name/ValuePerMile columns, then you don't need the hardcoded values in the expression. For example, if this is your 'Transport 1' list:

    /---------------------------------\
    | Name | ValuePerMile |
    |------------------+--------------|
    | Private car | 0.45 |
    | Company diesel | 0.16 |
    | Company petrol | 0.17 |
    \---------------------------------/

    Then the Items property for the dropdown should only be

    'Transport 1'

    Hope this helps!

  • Cseni Profile Picture
    70 on at

    Thank you, these all worked wonderfully!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard