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 / Filter gallery by item...
Power Apps
Answered

Filter gallery by item text not gallery source

(0) ShareShare
ReportReport
Posted on by 17

Hi there,

 

Is it possible to filter a gallery by a text component within a gallery item, not a column within the gallery datasource?

I have a text label component calculating and displaying the users distance to a location using their location and the items latitude and longitude. I would like to be able to filter the gallery by the closest point to the user.

 

any help would be great 🙂

 

thanks

 

rowan

Categories:
  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @rowanb ,

    Do you want to filer your Gallery Items based on the Text control value within this Gallery rather than a column from the Gallery data source?

     

    If you want to filer your Gallery Items based on the Text control value within this Gallery rather than a column from the Gallery data source, I afraid that there is no way to achieve your needs in PowerApps.

     

    When you want to filter your Gallery Items, the filter column must come from the data source the Gallery related to. You could not use Text control value within same Gallery as Filter column, it make no sense.

     

    I assume that you add columns in your data source to store the Latitude value and Longitude value of the target location, is it right? As an alternative solution, you could consider calculate the distance for each record in your data source, then add a temporary column (called "Distance") to store the distance value using AddColumns function, then sort your data source records by the "Distance" column in Ascending order.

    The sample formula looks like below (set the Items property of the Gallery to following) :

     

    SortByColumns(
     Search(
     AddColumns(
     Table1, 
     "Distance",
     ACOS(Cos(Radians(90-DeviceLat))*Cos(Radians(90-ThisItem.Latitude))+Sin(Radians(90-DeviceLat))*Sin(Radians(90-ThisItem.Latitude))*Cos(Radians(DeviceLong-ThisItem.Longitude)))*6371
     ),
     TextInput1.Text,
     "Address","City","Mall Name","Location / Dealer Name (Primary)","DBM/AM"
     ),
     "Distance",
     Ascending
    )

     

    or

    SortByColumns(
     AddColumns(
     Table1, 
     "Distance",
     ACOS(Cos(Radians(90-DeviceLat))*Cos(Radians(90-ThisItem.Latitude))+Sin(Radians(90-DeviceLat))*Sin(Radians(90-ThisItem.Latitude))*Cos(Radians(DeviceLong-ThisItem.Longitude)))*6371
     ),
     "Distance",
     Ascending
    )

    Please check and see if my response within the following thread would help in your scenario:

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Sort-gallery-by-closest-location-after-search-is-it-possible/m-p/183247

     

    Best regards,

  • rowanb Profile Picture
    17 on at

    hi @v-xida-msft 

     

    how would this work for multiple users using the app at the same time? If multiple users were using the app, wouldnt each user be trying to write distances to the same collumn within the data source? Is it possible write the gallery items ID and calculated distance to a collection to process locally, then sort collection by distance and have another gallery display to the data sources corresponding items? Or is it possible to even perform the calculation without using a gallery, but directly query the sharepoint list/data source and process within the app, essentially creating a table with UID, Latitude, Longitude, (Distance calculation based on user location and item location)?

     

    My use case is that i have about 250 locations on a large construction and i would like to plot pushpins on a bingmaps of the locations that are within 'X' distance of the user and have a gallery display the item information as well.. Ideally id like to figure out how to have 'X' be a slider component the the user can change.

     

    thanks for your help.

     

    Rowan

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @rowanb ,

    Based on the needs that you mentioned, I think the solution I provided above could solve your original issue (Filter Gallery items sort by the closest location).

     

    If the solution I provided above could achieve your original issue, please consider go ahead to click "Accept as Solution" to identify this thread has been solved.

     

    Multiple users could use your canvas app simultaneously, but they could not save data back to same record in your SP List simultaneously, it may cause Conflict issue within your app.

     

    You could consider save the calculated distance into a collection locally, then sort the collection by distance. If you want to plot multiple pushpins on a Bing Map within a specific distance, please check my response within the following thread:

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Bing-Maps-API/m-p/421181/thread-id/124683#M125044

     

    Firstly, you need to filter these records within specific distance against the calculated Distance column. You could try the following formula:

    Filter(
     AddColumns(
     Table1, 
     "Distance",
     ACOS(Cos(Radians(90-Location.Latitude))*Cos(Radians(90-LatitudeColumn))+Sin(Radians(90-Location.Latitude))*Sin(Radians(90-LatitudeColumn))*Cos(Radians(Location.Longitude-LongitudeColumn)))*6371
     ),
     Distance < 1000 // specify filter condition here e.g. filter records within 1000 km
     )

     

    Then you could take a try with the following Bing Map Imagery API to plot multiple pushpins (set the Image property of Image control to following😞

    "https://dev.virtualearth.net/REST/v1/Imagery/Map/AerialWithLabels?" & 
    Concat(
     Filter(
     AddColumns(
     Table1, 
     "Distance",
     ACOS(Cos(Radians(90-Location.Latitude))*Cos(Radians(90-LatitudeColumn))+Sin(Radians(90-Location.Latitude))*Sin(Radians(90-LatitudeColumn))*Cos(Radians(Location.Longitude-LongitudeColumn)))*6371
     ),
     Distance < 1000 // specify filter condition here e.g. filter records within 1000 km
     ),
     "pp=" & LatitudeColumn & "," & LongitudeColumn & ";21;" & City & "&"
    ) & "key=" & txtBingMapsKey.Text

     

    Please consider take a try with above solution, then check if the issue is solved.

     

    Best regards,

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 345 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 225

#3
M Bilal Khan Profile Picture

M Bilal Khan 192

Last 30 days Overall leaderboard