cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Bima_2003
Frequent Visitor

Sort and filter gallery by distance

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

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

View solution in original post

2 REPLIES 2
WarrenBelz
Super User
Super User

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

View solution in original post

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.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power Apps Community Call Jan. 2022 768x460.png

Power Apps Community Call

Please join us on Wednesday, January 19th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,254)