cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sjj9166
Level: Powered On

Adding a sort to a gallery filter with different data sources

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

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Adding a sort to a gallery filter with different data sources

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-oper...

 

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Super User
Super User

Re: Adding a sort to a gallery filter with different data sources

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.

Community Support Team
Community Support Team

Re: Adding a sort to a gallery filter with different data sources

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,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Sjj9166
Level: Powered On

Re: Adding a sort to a gallery filter with different data sources

 

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

 
Community Support Team
Community Support Team

Re: Adding a sort to a gallery filter with different data sources

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-oper...

 

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Solution Authors
Top Kudoed Authors
Users online (6,476)