---
schema_version: "1"
id: 48058a6fb2f764c20b89ce2cc23767347391b8b65d3b760bb77731c258dd65cd
title: DISTANCE
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/customize_functions_distance.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.customize_functions_distance.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: f37364ba9de10467abd54769cb5fe220ec59f1da9ccef454fd2fd1fe6e8f0ba6
description: Calculates the distance between two locations in miles or kilometers.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# DISTANCE

Calculates the distance between two locations in miles or kilometers.

## Use

`DISTANCE(mylocation1, mylocation2, 'unit')` and replace mylocation1 and mylocation2 with two location fields, or a location field and a value returned by the [GEOLOCATION](https://help.salesforce.com/s/articleView?id=platform.customize_functions_geolocation.htm&release=264.0.0&type=5 "Returns a geolocation based on the provided latitude and longitude. Must be used with the DISTANCE function.") function. Replace unit with mi (miles) or km (kilometers).

## Tips

- The DISTANCE function returns a number data type. Distance is always calculated in decimals, even if you’re displaying the geolocation notation in degrees, minutes, and seconds in the user interface. Specify the number of decimal places to show when you create a custom field.
- The DISTANCE function isn’t available in reports, but it can be used in list views. To use DISTANCE in your reports, set up a formula field, and then reference the field in your reports.
- DISTANCE is the only formula function that can use [GEOLOCATION](https://help.salesforce.com/s/articleView?id=platform.customize_functions_geolocation.htm&release=264.0.0&type=5 "Returns a geolocation based on the provided latitude and longitude. Must be used with the DISTANCE function.") parameters.
- There are limitations on DISTANCE accuracy and equality calculations.
    
    - DISTANCE supports only the logical operators > and <, returning values within (<) or beyond (>) a specified radius.
    - Distance is calculated as a straight line, regardless of geography and topography between the two points.
    
    For more details, see “[How SOQL Calculates and Compares Distances](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_geolocate.htm#geolocation_how_distance_is_calculated)” in the SOQL and SOSL Reference.

![Example: Distance Between Two Geolocation Fields](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_example.png)

Example: Distance Between Two Geolocation Fields

`DISTANCE(warehouse_location__c, store_location__c, 'mi')`

This formula returns the distance, in miles, between the warehouse and the store. In this example, `warehouse_location__c` and `store_location__c` are the names of two custom geolocation fields.

![Example: Distance Between an Address Field and a Geolocation Field](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_example.png)

Example: Distance Between an Address Field and a Geolocation Field

`DISTANCE(BillingAddress, store_location__c, 'mi')`

This formula returns the distance, in miles, between an account’s billing address and a store. In this example, `BillingAddress` is the standard billing address field on an Account object, and `store_location__c` is the name of a custom geolocation field.

![Example: Distances with Conditions](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_example.png)

Example: Distances with Conditions

`IF(DISTANCE(warehouse_location__c, ShippingAddress, 'mi')<10, "Near", "Far")`

This formula updates a text formula field to Near if the distance between the warehouse and the account shipping address compound field is less than 10 miles. Otherwise, it updates the text field to Far.

![Tip](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_tip.png)

Tip Although DISTANCE can be calculated in miles or kilometers, the unit isn't returned in the calculation. If possible, include the unit of measure in the name of your distance formula field, so users know whether the distance is in miles or kilometers.