web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Sort and filter galler...
Power Apps
Answered

Sort and filter gallery by distance

(0) ShareShare
ReportReport
Posted on by 35

Hello PowerApps Guru.

I have a gallery with location details in it.
I would like to filter the items using my controls (TextSearchBox1 and Dropdown1).
And once they're filtered, I'd also like to sort the distance by adding a new column called dist.

 

Screenshot 2021-11-28 122721.jpg
Here is what I write for Gallery items:

 

SortByColumns(
 Search(
 If(
 Dropdown1.Selected.Value = "ALL",
 DATA_SHEET,
 Filter(
 DATA_SHEET,
 Kategori.Value = Dropdown1.Selected.Value
 )
 ),
 TextSearchBox1.Text,
 "field_Display",
 "field_Ruas",
 "field_Nama",
 "field_Kota_lokasi"
 ),
 AddColumns
 (DATA_SHEET,
 "dist",
 3958.818 * ((2 * Asin(Sqrt((Sin((Radians(Location.Latitude) - Radians(Latitude)) / 2) ^ 2) + Cos(Radians(Location.Latitude)) * Cos(Radians(Latitude)) * (Sin((Radians(Location.Longitude) - Radians(Longitude)) / 2) ^ 2)))))
 ),
 "dist",
 If(
 SortDescending1,
 Descending,
 Ascending
 )
)


// this is returning red lines 😒

 

I've searched the forum but didn't seem to find the answer.

Helps and suggestions will be greatly appreciated.

 

Thank you

 

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,963 Most Valuable Professional on at

    Hi @Bima_2003 ,

    I think I have the brackets on your distance calculation correct - if not, you may have to try adding or removing one at a time

    SortByColumns(
     Search(
     AddColumns(
     Filter(
     DATA_SHEET,
     (
     Dropdown1.Selected.Value = "ALL" ||
     Kategori.Value = Dropdown1.Selected.Value
     )
     ),
     "dist",
     3958.818 * 
     (
     (
     2 * Asin(
     Sqrt(
     (Sin((Radians(Location.Latitude) - Radians(Latitude)) / 2) ^ 2) + 
     Cos(Radians(Location.Latitude)) * Cos(Radians(Latitude)) * 
     (Sin((Radians(Location.Longitude) - Radians(Longitude)) / 2) ^ 2)
     )
     )
     )
     )
     ),
     TextSearchBox1.Text,
     "field_Display",
     "field_Ruas",
     "field_Nama",
     "field_Kota_lokasi"
     ),
     "dist",
     If(
     SortDescending1,
     Descending,
     Ascending
     )
    )

     

    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

  • Bima_2003 Profile Picture
    35 on at

    I gave it a try and it helped me answer my question.

    (didn't have to add or remove the brackets. They're correct btw)

     

     

    Thank you very much.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 189 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 139

Last 30 days Overall leaderboard