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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Adding a sort to a gal...
Power Apps
Answered

Adding a sort to a gallery filter with different data sources

(0) ShareShare
ReportReport
Posted on by 25

The filter is working perfect - I want to add a sort on the value "Days since last visit" "Days since last visit" but this field is in a collection that is different than the gallery filter.

ChecklistImage.PNG

Filter Source

Filter(HIERARCHY,(CM_Email=vCurrentUser.Email) &&
(StartsWith(StoreType,ThisType) &&
(StartsWith(Store_id,TextSearchBox_1.Text) ||
StartsWith(STORE_NAME, TextSearchBox_1.Text) ||
StartsWith(CITY, TextSearchBox_1.Text))
))

Sort source

ClearCollect(
 ColSession1,
 AddColumns(
 GroupBy(
 Store_Visit,
 "StoreId",
 "Store_Name",
 "DaysSinceLastVisit",
 "Visit_Date",
 "LastVDate"
 ),
 "LastVisitDate",
 Text(
 Max(
 LastVDate,
 Visit_Date
 ),
 "[$-en-US]mm/dd/yyyy"
 )
 )
)

Any thoughts on how to accomplish this?

 

Thanks

Steve

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @Sjj9166 

    You can use the AddColumns() and Lookup() functions to bring in the date from the second data source as long as there is a common column in both datasources. In the example from the documentation,  https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-table-shaping

    AddColumns( RealEstateAgents, 
    	"Listings", 
    	Filter( '[dbo].[AllListings]', ListingAgentName = AgentName ) 
    )

     In your case, you would pull in the date from the second datasource.

  • v-xida-msft Profile Picture
    on at

    Hi @Sjj9166 ,

    Could you please share a bit more about your scenario?

    Is there a relationship between the HIERARCHY data source and the Store_Visit data source?

     

    I assume that the HIERARCHY data source and the Store_Visit data source set up a relationship based on the Store_id column value, is it true?

     

    I have made a test on my side, please take a try with the following workaround:

    Set the OnSelect property of the "Sort" icon to following formula:

    UpdateContext({SortDescending1: !SortDescending1})

    Set the Items property of the Gallery to following:

     

    SortByColumns(
    Filter(
    AddColumns(HIERARCHY, "DaysSinceLastVisit", LookUp(ColSession1, StoreId = HIERARCHY[@Store_id], DaysSinceLastVisit)),
    CM_Email = vCurrentUser.Email, StartsWith(StoreType,ThisType), StartsWith(Store_id, TextSearchBox_1.Text) || StartsWith(STORE_NAME, TextSearchBox_1.Text) || StartsWith(CITY, TextSearchBox_1.Text) ),
    "DaysSinceLastVisit",
    If(SortDescending1, Descending, Ascending)
    )

     

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

     

    Best regards,

     

  • Sjj9166 Profile Picture
    25 on at
     

    ChecklistImage1.PNG

    Yes Hierarchy and Colsession1 are related by StoreId but when I try your suggestion I'm presented with no stores.  Also what is the '@' before Store_id & what does it do? Thanks again

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

    Hi @Sjj9166 ,

    Based on the issue that you mentioned, I have made a test on my side, and don't have the issue that you mentioned. I think the formula I provided above is proper.

     

    Please check if the ColSession1 collection is populated with proper records in your app. I assume that you have already executed the ClearCollect(...) formula successfully within your app, and the ColSession1 has been populated with proper records.

     

    In addition, the "@" represents the Disambiguation operator within PowerApps, which could recognize what data source the field is from.

    Please check the following article for more details:

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/operators#disambiguation-operator

     

    If you do not want to include the "@" operator in your app, please modify your formula as below:

    Set the Items property of the Gallery to following:

    SortByColumns(
    Filter(
    AddColumns(HIERARCHY, "DaysSinceLastVisit", LookUp(ColSession1, StoreId = Store_id, DaysSinceLastVisit)), /* <-- Stored_id column is from the HIERARCHY data source */
    CM_Email = vCurrentUser.Email, StartsWith(StoreType, ThisType), StartsWith(Store_id, TextSearchBox_1.Text) || StartsWith(STORE_NAME, TextSearchBox_1.Text) || StartsWith(CITY, TextSearchBox_1.Text) ),
    "DaysSinceLastVisit",
    If(SortDescending1, Descending, Ascending)
    )

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

     

    Note: Also please check if the Store_id column value in your Hierarchy could match the corresponding value in your Colsession1.

     

    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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard