cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Hnl
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

@Hnl ,

Is this now solved?

View solution in original post

4 REPLIES 4
WarrenBelz
Super User
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(
   AddColumns(
      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

Hnl
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?

Hnl
Frequent Visitor

Oh nvm I got it now. Thank you!

@Hnl ,

Is this now solved?

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

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

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (2,320)