# IF statement for Distance - Flow

I am trying to create a screen flow without using a loop to display "Nearby Accounts" (within 10 miles). However I am getting an error as seen in the below screenshot. I am fairly new to using formulas in flow so any help would be much appreciated.

Here is the screen shot of the formula in a Collection Filter:

Formula: IF(DISTANCE( GEOLOCATION({!recordId.BillingLatitude} , {!recordId.BillingLongitude}), GEOLOCATION({!currentItem_Collect_Accounts_WIthin_10_miles.BillingLatitude}, {!currentItem_Collect_Accounts_WIthin_10_miles.BillingLongitude}), 'mi') <10)

Here is an overview of my flow:

For context I am not using a loop because our org has too many accounts as when implementing a loop the number of iterations are exceeded.

What I want the formula in the collection filter to achieve is to return Accounts that are within 10 miles of an Account.

• Please edit your post to include the error text and show the details of what the step is doing. Jan 20, 2023 at 16:23
• @DavidCheng sorry about this I forgot to add the screenshot of the formula. I hope this makes sense. Jan 20, 2023 at 16:41
• If `DISTANCE` and `GEOLOCATION` are permitted in a formula, you need to make sure the `IF` has the three parameters. So here something like `IF(DISTANCE(...) < 10, TRUE, FALSE)` Jan 20, 2023 at 16:49
• I must say, it's annoying you cannot do a `DISTANCE` calculation/filter in the `Get Records` element itself. Jan 20, 2023 at 17:50
• Hi guys, I have managed to get this working! @PhilW thank you. I have achieved it by using the following formula in the Collection Filter: IF(DISTANCE( GEOLOCATION({!recordId.BillingLatitude} , {!recordId.BillingLongitude}), GEOLOCATION({!currentItem_Collect_Accounts_WIthin_5_miles.BillingLatitude}, {!currentItem_Collect_Accounts_WIthin_5_miles.BillingLongitude}), 'mi') <5, TRUE, FALSE) Jan 23, 2023 at 8:53

The `IF` function always takes three parameters. You need to update your `IF` so it has the condition and the two resulting values. Since you are only interested in whether the condition is met (or not) you need to make it something like:
``````IF(DISTANCE(...) < 10, TRUE, FALSE)
I have left out the detail passed to the `DISTANCE` function for clarity.
This says, if the condition (here the check for distance) is met then return `TRUE` otherwise return `FALSE`.