Skip to main content

Notifications

PowerApps, Dataverse,& Bing Maps: Service to Client, Drive Rating

 AhmedSalih_0-1695982085207.jpeg

Section 1: The Drive Rating System

A. Overview

The drive rating system calculates a score of 10, representing how smooth the drive from Memphis to the client's city would be based on the distance only. The higher the score, the smoother the drive.

 

B. Calculating Distance

The distance between the client's city and Memphis is calculated using Bing Maps API. It's then converted to miles using the formula:

Distance in miles = Distance in kilometers / 1.609

 

C. Drive Rating Formula

The rating is obtained by scaling the distance:

Rating = 10 − ( Distance in miles / 3000) × 10 )

 

Section 2: Gas Price Rating

A. Overview

Inside the Accounts gallery, an embedded gallery displays the price cost by changing the color of an icon. The rating for the gas price is out of 4.

 

B. Calculating Price Tag

The Price Tag is derived by considering the distance and scaling it down to a 4-point rating system:

Price Tag = Round(4−(Distance in miles / 3000 × 4 ), 0)

 

C. Color Coding

Depending on the comparison between the current item's value and the Price Tag, the icon color changes:

If less than Price Tag: Gray (RGBA(219, 219, 219, 1))

Else: Orange (Color.Orange)

 


 

Section 3: Code and Implementation

A. Utilizing Dataverse Account Table

The core of this demo is the System Dataverse Accounts table (it includes sample data if the environment is provisioned with sample data). We retrieve the necessary client information to feed into our algorithms by accessing this rich database.

🎈You can use any table with a column with a city name value, but just make sure you change the Power Fx formulas to reflect your table and column names.

 

B. Integrating Bing Maps API

Bing Maps API is pivotal in this solution, allowing us to calculate the travel distance between the client's city and Memphis.

To sign up for a free API key, go to Bing Maps Dev Center - Bing Maps Dev Center (bingmapsportal.com) 

✅ Sign up or log in if you have an account.

✅ Go to my account and select my keys.

✅ Create a new key or copy a new one. 

✅ You will use this key when you add the BingMaps connector to your PowerApps.

 AhmedSalih_1-1695982116299.jpeg

C. Galleries and Drive Rating

🚀 1. Main Accounts Gallery

The Accounts Gallery control displays the Accounts from the Dataverse, and each Account's drive smoothness rating is determined using the Bing Maps API with the following formula that is used for the Default Property of the Rating Control:

With(

    {

        ClientDistanceFromMemphis: BingMaps.GetRouteV2(

            ThisItem.'Address 1: City',

            "Memphis"

        ).travelDistance / 1.609

    },

    10 - (ClientDistanceFromMemphis / 3000 * 10)

)

 

🚀 2. Embedded Gallery for Gas Price Rating

An embedded gallery visualizes the gas price rating inside the main Accounts gallery, again utilizing Bing Maps API for distance calculations.

 

🚀 3. Gas Price Rating Formula

The icon's color inside the embedded gallery changes based on the gas price rating, using this formula:

With(

    {ClientDistanceFromMemphis: lbl_DistanceInMiles.Text},

    With(

        {

            PriceTag: Round(

                4 - (ClientDistanceFromMemphis / 3000 * 4),

                0

            )

        },

        If(

            ThisItem.Value < PriceTag,

            RGBA(219, 219, 219, 1),

            Color.Orange

        )

    )

)

 

Conclusion

This PowerApps use case combines geographic data and a unique rating algorithm to convey insights about driving experiences and gas costs. By creatively using galleries, distance calculation, and color coding, complex data is made approachable. Whether you're a business looking to enhance client communication or a developer seeking inspiration, this application showcases the power and flexibility of PowerApps.

 

To try this App:

GitHub Repo

Download the unmanaged solution 

Import the unmanaged solution to your environment

Add Bing Map Connector to your Environment. Make sure you use your key. Here is how to create one.

Open the Canvas app in Edit mode

Remove the Bing Map connector and re-add it to add your connector.

 

 

 

Comments

*This post is locked for comments