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
Super User

@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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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
Super User

@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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,270)