cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JV_DXB
Frequent Visitor

Toggle Button - Filter

I have a new Toggle Button and I would like to Filter the data as per Toggle - On or Off. If Toggle is ON I want the app to show only those records where Status = Open. Status is the Column Name. 

 

I am new to Powerapps. 

1 ACCEPTED SOLUTION

Accepted Solutions

@JV_DXB 

 

Looking at the formula you provided I think you are wanting to use the toggle to show items in a table with either a CLOSED status if the toggle is off or an OPEN status if the toggle is on. You also need to be able to use a text field to search content at the same time.

 

You will need to pass the filtered table into the search function so the search is performed only on these results. Can you try using the following code in the items property of a gallery or table:

If(Toggle1.Value,  
    SortByColumns(
        Search(
            Filter(Table1, 'Issue Status' = "OPEN"), 
            TextSearchBox1.Text, 
            "Description","From_x0020_","Info_x002f__x0020_Action","Issue_x0020_Status"
            ),
        "Date", 
        If(SortDescending1, Descending, Ascending)
    ),
    SortByColumns(
        Search(
            Filter(Table1, 'Issue Status' = "CLOSED"), 
            TextSearchBox1.Text, 
            "Description","From_x0020_","Info_x002f__x0020_Action","Issue_x0020_Status"
            ),
        "Date", 
        If(SortDescending1, Descending, Ascending)
    )
)

Hope this is what you were looking for Robot Happy

View solution in original post

9 REPLIES 9
JimmyBecks
Resolver I
Resolver I

Hi @JV_DXB,

 

You can get the value of a toggle control to determine whether it is on or off (true or false). You can then use an If function to filter your data based on this value.

 

 

If(
    Toggle1.Value, //Will return true or false
    Filter( //If the toggle is on filter collection of data
        MyCollection,
        Status = "Open"
    ),
    MyCollection // If the toggle is off just show the unfiltered collection
)

//Replace MyCollection and Toggle1 with the name of your equivalent dataset and control

 

 

You could set the items property of a gallery to this and it would filter based on if the toggle is on or off.

 

Hope that helps Robot Happy

Hi @JimmyBecks ,

 

Where do I add this code? To Toggle Button or browse gallery? 

@JV_DXB 

 

If you wanted to display the data in a gallery you will need to add it to the items property of the gallery, where you would normally have the data source you want to show in the gallery (in my example this is MyCollection)

 

 

v-yuxima-msft
Community Support
Community Support

Hi @JV_DXB ,

 

What is your data source?And what is the column type of Status?

Do you test with @JimmyBecks 's suggestion?If it works ok, please accept it as as solution.

I test with SP list and two columns types, one is single line, one is choice type

Data source:'20190523test' (my SP list name)

20190523ToggleFilter1.PNG

Status_S (single line)

Status_Choice(choice type)

 

App Test:

20190523ToggleFilter2.PNG

If the column type is single line, Gallery1.Items=If(Toggle1.Value=true,Filter('20190523test',Status_S = "Open"),'20190523test')

If the column type is Choice,Gallery1.Items=If(Toggle1.Value=true,Filter('20190523test',Status_Choice.Value = "Open"),'20190523test')

 

Hope this could be helpful.

 

Best Regards.

Yumia

Hello,

I have tried the below code as guided by @JimmyBecks  but when I turn on Toggle I cannot search

 

If(Toggle1.Value, Filter(Table1, 'Issue Status' = "OPEN"), SortByColumns(Search(Table1, TextSearchBox1.Text, "Description","From_x0020_","Info_x002f__x0020_Action","Issue_x0020_Status"), "Date", If(SortDescending1, Descending, Ascending)))

Hi @JV_DXB 

 

I think you wrong understanding of the functions using.

Could you please reference this firstly?

function-if

function-filter-lookup

function-sort

 

Hope this could be helpful.

 

Best Regards.

Yumia

@JimmyBecks @v-yuxima-msft 

 

Which function would give me the desired result? When Toggle is on I want to show all items with Status "Open" and when toggle is off, I want to show all items with Status "Closed". I am able to achieve this with below code but unable to search when toggle is ON.

 

If(Toggle1.Value, Filter(Table1, 'Issue Status' = "OPEN"), SortByColumns(Search(Table1, TextSearchBox1.Text, "Description","From_x0020_","Info_x002f__x0020_Action","Issue_x0020_Status"), "Date", If(SortDescending1, Descending, Ascending)))

@JV_DXB 

 

Looking at the formula you provided I think you are wanting to use the toggle to show items in a table with either a CLOSED status if the toggle is off or an OPEN status if the toggle is on. You also need to be able to use a text field to search content at the same time.

 

You will need to pass the filtered table into the search function so the search is performed only on these results. Can you try using the following code in the items property of a gallery or table:

If(Toggle1.Value,  
    SortByColumns(
        Search(
            Filter(Table1, 'Issue Status' = "OPEN"), 
            TextSearchBox1.Text, 
            "Description","From_x0020_","Info_x002f__x0020_Action","Issue_x0020_Status"
            ),
        "Date", 
        If(SortDescending1, Descending, Ascending)
    ),
    SortByColumns(
        Search(
            Filter(Table1, 'Issue Status' = "CLOSED"), 
            TextSearchBox1.Text, 
            "Description","From_x0020_","Info_x002f__x0020_Action","Issue_x0020_Status"
            ),
        "Date", 
        If(SortDescending1, Descending, Ascending)
    )
)

Hope this is what you were looking for Robot Happy

View solution in original post

@JimmyBecks 

 

Worked. Thanks.

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

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors
Users online (2,276)