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

Combine Filter and Sorting in Gallery

Hello community,

I have the following problem:

 

I only want to see the data in a gallery that I have previously filtered and still want to have the option to search for individual items.

 

This is how it looks like:

Marvin_Heile_0-1620391183833.png

 

 

I figured out how to create the code for filtering via the text search box and how to filter via the tiles individually:

 

Here is my code for filtering via the text search box: 

SortByColumns(Search([@Table1], TextSearchBox1.Text, "FIXEDASSETNUMBER","ACTIVITYCODE","BARCODE"), "FIXEDASSETNUMBER", If(SortDescending1, Descending, Ascending))

 

Here is the code for filtering via the tiles:

 

If(

    Gallery1.Selected.Value = "All",

    Filter(

        Table1,

        StartsWith(

            "FIXEDASSETNUMBER",

            TextSearchBox1.Text

        )

    ),

    Filter(

        Table1,

        StartsWith(

            "FIXEDASSETNUMBER",

            TextSearchBox1.Text

        )&& OVERDUE = Gallery1.Selected.Value

    )

)

 

My question: How can I combine this code?

 

(I am working with a excel file as my data source)

 

Thank you very much for your help!

 

I hope the question has not been asked more often. Unfortunately, I have not found a suitable answer to this.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@Marvin_Heile 

You are performing a Search and a StartsWith on the same column and the same TextInput.

Please consider changing your Formula to the following:

SortByColumns(
    Search(
        Filter(
            Table1,
            (Gallery1.Selected.Value = "All" || OVERDUE = Gallery1.Selected.Value)
        ),
        TextSearchBox1.Text, 
        "FIXEDASSETNUMBER","ACTIVITYCODE","BARCODE"
    ),        
    "FIXEDASSETNUMBER", 
    If(SortDescending1, Descending, Ascending)
)

This will filter your Table based on the selected value of the Gallery and then perform the search on that resultant table.  Then it will sort by the desired column.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

3 REPLIES 3
CarlosFigueira
Power Apps
Power Apps

You can use the result of your filter to your Search function

SortByColumns(
    Search(
        If(
            Gallery1.Selected.Value = "All",
            Filter(
                Table1,
                StartsWith(
                    "FIXEDASSETNUMBER",
                    TextSearchBox1.Text
                )
            ),
            Filter(
                Table1,
                StartsWith(
                    "FIXEDASSETNUMBER",
                    TextSearchBox1.Text
                )&& OVERDUE = Gallery1.Selected.Value
            )
        ),
        TextSearchBox1.Text,
        "FIXEDASSETNUMBER", "ACTIVITYCODE", "BARCODE"),
    "FIXEDASSETNUMBER",
    If(SortDescending1, Descending, Ascending))

You can also combine the two "branches" of the If function in a single one to make the expression a little smaller:

SortByColumns(
    Search(
        Filter(
            Table1,
            StartsWith(
                "FIXEDASSETNUMBER",
                TextSearchBox1.Text
            ),
            Gallery.Selected.Value = "All" Or OVERDUE = Gallery1.Selected.Value
        ),
        TextSearchBox1.Text,
        "FIXEDASSETNUMBER", "ACTIVITYCODE", "BARCODE"),
    "FIXEDASSETNUMBER",
    If(SortDescending1, Descending, Ascending))

Hope this helps!

Hi @CarlosFigueira ! 

Thank you for your fast response. 

Unfortunatelly, both proposed solutions doesnt work 100%. If I integrate your code, only the tile filtering works. As soon as I enter a text in the search bar, no more data is displayed.

Do you need more information from my side?

RandyHayes
Super User III
Super User III

@Marvin_Heile 

You are performing a Search and a StartsWith on the same column and the same TextInput.

Please consider changing your Formula to the following:

SortByColumns(
    Search(
        Filter(
            Table1,
            (Gallery1.Selected.Value = "All" || OVERDUE = Gallery1.Selected.Value)
        ),
        TextSearchBox1.Text, 
        "FIXEDASSETNUMBER","ACTIVITYCODE","BARCODE"
    ),        
    "FIXEDASSETNUMBER", 
    If(SortDescending1, Descending, Ascending)
)

This will filter your Table based on the selected value of the Gallery and then perform the search on that resultant table.  Then it will sort by the desired column.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (76,950)