cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Combining Filter and Sort

I have the following Sort in my Gallery:

 

SortByColumns(Search('Table', TextSearchBox1.Text, "First_Name", "Surname","Address_Line_1"), "Postcode")

 

My question is, is there a way to Filter the results before Sorting? Essentially, I want to add a Filter that checks if Area_ID is equal to something specific such as 12345 and then, once filtered, I want the Sort above to kick in. Any suggestions? I tried combining the Filter and Sort into one statement, but I alwas seem to get errors.

1 ACCEPTED SOLUTION

Accepted Solutions

That should work - you should be able to compose multiple table operations (sorting, searching, filtering, etc.). For example, in your scenario, try something like this (you may need to change the field names / values):

 

SortByColumns(
    Search(
        Filter(
            'Table',
            Area_ID = 12345),
        TextSearchBox1.Text,
        "First_Name",
        "Surname",
        "Address_Line_1"),
    "Postcode")

View solution in original post

10 REPLIES 10

That should work - you should be able to compose multiple table operations (sorting, searching, filtering, etc.). For example, in your scenario, try something like this (you may need to change the field names / values):

 

SortByColumns(
    Search(
        Filter(
            'Table',
            Area_ID = 12345),
        TextSearchBox1.Text,
        "First_Name",
        "Surname",
        "Address_Line_1"),
    "Postcode")

Nevermind, the above is working now. Just had to refresh my data to fix the bug.

Actually, just noticed a problem @CarlosFigueira. If I filter by Area_ID first, and then enter a postcode, the search seems to overwrite the filter and show Area_IDs that should be filtered out. For example...

 

Area_ID  PostCode

123         HA0 111

123         HA0 112

123         HA0 113

111          HA2 11G

 

If I filter the Area_ID by 123, only the first 3 results show which is good. However, if I then search by a postcode such as "HA", the fourth result with the 111 Area_ID will show up because the search is overwriting the filter. I'm hoping to get the two working together so that once I filter by a Area_ID, the search will only act on the filtered results that are showing.

Do you have any solution to the last post, to avoid that the search-function is overwriting the filter?
Please update

@Tezz233 I don't see the problem of the search overriding the filter... To try to reproduce this scenario, here's what I did:

- Added a button to an empty screen with the following OnSelect expression:

ClearCollect(coll,
    {Area_ID:123, PostCode:"HA0 111"},
    {Area_ID:123, PostCode:"HA0 112"},
    {Area_ID:123, PostCode:"HA0 113"},
    {Area_ID:111, PostCode:"HA2 11G"})

Added a gallery, and inside the gallery added a label with the expression

ThisItem.Area_ID & " - " & ThisItem.PostCode

Then set the Items property of the gallery to the filter/search expression:

Search(Filter(coll, Area_ID = 123), "HA", "PostCode")

The gallery displayed only the three items with Area_ID = 123, it didn't display the fourth one.

 

To check if this is a problem with delegation, I also created a new table in a SQL Server database:

create table forumpost_85212 (
    Id int identity(1,1) primary key,
    Area_ID int,
    PostCode nvarchar(max)
)

And added four items to it:

insert into forumpost_85212 (Area_ID, PostCode) VALUES (
    123, 'HA0 111'
)

insert into forumpost_85212 (Area_ID, PostCode) VALUES (
    123, 'HA0 112'
)

insert into forumpost_85212 (Area_ID, PostCode) VALUES (
    123, 'HA0 113'
)

insert into forumpost_85212 (Area_ID, PostCode) VALUES (
    111, 'HA1 11G'
)

Likewise, after adding a data source pointing to that table, I set the gallery's Items property to:

Search(Filter('[dbo].[forumpost_85212]', Area_ID = 123), "HA", "PostCode")

And once again I only see three items.

 

Can you post more details on where you are seeing the Search function overriding the Filter expression?

Hi,

 

I know this an old post but I'm having the same problems, the Search function always overrides the Filter results. I have tried all the suggestions in posts but always the same, the results are correctly filtered by the Dropdown1 & Dropdown1_2 selections but if I search via TextSearchBox1.Text the results are from the entire database and not filtered.

 

SortByColumns(

    Search(

              Filter('MG Site',

                        SiteID = Dropdown1.Selected.Value, EntType = Dropdown1_2.Selected.Value

                        ),

                        TextSearchBox1.Text,

                        "UnitNo",

                        "IPAdd),

                        "IPAdd",

If (SortDescending1, Descending, Ascending)

)

 

Would appreciate some help please.

 

Jeff

Hi Jeff,

Realise this is an old post!

But came across it researching a similar (though not exactly the same) question.

 

For me it's liked 'related' or 'constrained' dropdowns.

User selects the "Market" and then a list of "Manufacturing Centres" are related to "Markets".

I couldn't seem to combine the sort and filter. But I used ClearCollect statement in the "OnSelect", seemed to work OK so far!

e.g. (this is on the 2nd field!)

OnSelect
ClearCollect(tempCollection,Sort('[dbo].[vwMarketManufacturingCentre]',MANUFACTURINGCENTRE))

 

And the "Items" field (the other options mean it can be blank, and blank on selection).

Ungroup(Table({Item:Blank()},{Item:Filter(tempCollection,MARKETNAME = MarketSelection_1.Selected.Value)}),"Item")

 

It seems to work - probably needs more testing (I'm expecting to need to "Clear" the tempCollection collection!

 

Here's another more complicated "Sort and Filter" example.

It worked when my other approach didn't!

Ungroup(Table({Item:Blank()},{Item:Distinct(Filter(Sort('[dbo].[KAPMT_MAIN_VIEW_2]',PROCESS_STEP_DESC,Ascending),
APPLICATION=ApplicationSelection_1.Selected.Value,SITE_DESCRIPTION=SiteSelection_1.Selected.Value,MANUFACTURINGCENTRE=ManufacturingCentreSelection_1.Selected.Value,MARKETNAME=MarketSelection_1.Selected.Value),PROCESS_STEP_DESC)}),"Item")

Bumping this thread up again.  I have run into an issue with my app only pulling 500 records and I understand that limit can be adjusted a bit but what I want to do is just filter the retrieval of records to ones where my office365 user display name matches the person who submitted the record (which is also the office 365 display name).  

 

I'm using where FormQs is a live onedrive document where the data resides, Field1 is the name of who submitted the record and Field 2 is the location:  

 

SortByColumns(Search([@FormQs], TextSearchBox1.Text, "Field1","Field2_(Campus)"), "Date_of_Visit", If(SortDescending1, Descending, Ascending))

 

I want the app to only pull records where in 'Field1' the name agrees with the logged in user and then allow for search by 'Field2' and Sort by 'Date of Visit'.  

 

My text search box contains by default: Office365Users.MyProfile().DisplayName which I was trying to use as a workaround so everyone doesn't see everyone else's records but I think it is still pulling all of the records down because if you remove the name that appears in the default we see all records of course. 

 

I'm trying to reduce the number of records the app pulls when it loads for each user and then still allow searching and sorting from the gallery.  

 

Thank you

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (799)