cancel
Showing results for
Did you mean:
Frequent Visitor

## Calculating distance (km) with lat/long on dataset larger then 2000

Hey, I want to sort a gallery with the nodes closest to the user, but I have to do it on a dataset of around 3700 rows. I have already done it with 2000 rows (because of the limit), but I am struggling with that in the last 1700 rows there might be a node closer then in the first 2000s.

Any ideas?

The dataset is in dataverse btw.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

@Hnl ,

Is this now solved?

4 REPLIES 4
Super User

HI @Hnl ,

If you have under 4,000 items, you can try this

``````With(
{
wLow:
Sort(
YourList
ID
),
wHigh:
Sort(
YourList,
ID,
Descending
)
},
ClearCollect(
colWhatever,
wLow,
Filter(
wHigh,
!(ID in wLow.ID)
)
)
)``````

then the Items of the gallery

``````Sort(
colWhatever,
"Distance",
With(
{
wLat1: YourLatitudeField,
wLat2: Location.Latitude,
wLong1: YourLognitudeField,
wLong2: Location.Longitude,
wCalc: 0.0174532925199432
},
12742 * Asin(Sqrt(0.5 - Cos((wLat1 - wLat2) * wCalc)/2 +
Cos(wLat1 * wCalc) * Cos(wLat2 * wCalc) * (1 - Cos((wLong1 - wLong2) * wCalc)) / 2))
)
),
Distance
)``````

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Frequent Visitor

Thanks you for the help. I am now trying your solution, but "colWhatever" collection does get the amount of rows correct, but none of the values are there. Every column is blank. I think it has to do with the first bit of code. Do you see any faults in it?

Frequent Visitor

Oh nvm I got it now. Thank you!

Super User

@Hnl ,

Is this now solved?

Announcements

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.