web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filtering button for "...
Power Apps
Suggested Answer

Filtering button for "Others" data problem

(1) ShareShare
ReportReport
Posted on by 6
Hi, I'm new to Powerapps and trying to add a button that filters out data in a gallery taken from an excel column, in the sense that it exclude certain values, but my button uses Set(varfilter), and I'm not sure how I would implement Not( ) or ! to remove the unwanted data.  
 
Currently, my gallery items is: 
 
With({_Data:Filter(Permit_V2,'Permit Status'="Approved" || 'Permit Status'= "Extended",IsBlank(VarFilter) ||'Location of work'= VarFilter)},Filter(_Data,IsBlank(DatePicker1.SelectedDate)||DateValue(Dateofworktobedone)=DatePicker1.SelectedDate))
 
 
And my button is (I want to exclude data such as "I-plant" from the varfilter): 
 
Set(VarshowGroup3, true) ; Set(VarFilter, "I-Plant") ; UpdateContext({FilterValue: "Location of work"}) || Set(VarFilter, "Approved") ; UpdateContext({FilterValue: "Permit Status"})
Categories:
I have the same question (0)
  • Suggested answer
    Valantis Profile Picture
    6,735 on at
     
    To show records where Location of work is NOT a specific value, you don't set VarFilter to the excluded value, you need a separate variable approach.
    The cleanest way for an "Others" button: use a different variable to hold the exclusion list and adjust your gallery formula.
     
    Button OnSelect:
    Set(VarFilter, ""); Set(VarExclude, true)
    Gallery Items (updated):
    With(
     {_Data: Filter(Permit_V2,
     'Permit Status' = "Approved" || 'Permit Status' = "Extended",
     If(VarExclude,
     'Location of work' <> "I-Plant",
     IsBlank(VarFilter) || 'Location of work' = VarFilter
     )
     )},
     Filter(_Data,
     IsBlank(DatePicker1.SelectedDate) || DateValue(Dateofworktobedone) = DatePicker1.SelectedDate
     )
    )
     
    For your other location buttons (the ones that filter TO a specific value):

    Set(VarFilter, "LocationName"); Set(VarExclude, false)
    For a button that shows all:
    Set(VarFilter, ""); Set(VarExclude, false)
     
    This keeps the same gallery formula but switches between include mode (VarFilter) and exclude mode (VarExclude) depending on which button was pressed.
     
      Best regards,

    Valantis   ✅ If this helped solve your issue, please Accept as Solution so others can find it quickly.

    ❤️ If it didn’t fully solve it but was still useful, please click “Yes” on “Was this reply helpful?” or leave a Like :).

    🏷️ For follow-ups  @Valantis.

    📝 https://valantisond365.com/ 💼 LinkedIn ▶️ YouTube
  • Suggested answer
    11manish Profile Picture
    3,333 on at
    Try below :
     
    With(
        {
            _Data:
            Filter(
                Permit_V2,
                ('Permit Status' = "Approved" || 'Permit Status' = "Extended") &&
                (IsBlank(VarFilter) || 'Location of work' = VarFilter) &&
                'Location of work' <> "I-Plant"
            )
        },
        Filter(
            _Data,
            IsBlank(DatePicker1.SelectedDate) ||
            DateValue(Dateofworktobedone) = DatePicker1.SelectedDate
        )
    )
     
  • Suggested answer
    Haque Profile Picture
    3,653 on at
     
     
    Lets work on button’s OnSelect to set the filter value for exclusion.  Without a variable (VarFilter), we can set variable that inidicates we can exclude the value:
     
    Set(VarShowGroup3, true);
    Set(VarFilter, "ExcludeIPlant");
    UpdateContext({FilterValue: "Location of work"})
    The above code confirms VarShowGroup3 set to true, value (ExcludeIPlant) has been assigned to VarFilter. Also, "Location of work" has been set to FilterValue.
     
     
    Now we can update gallery’s Items property - let's use VarFilter to exclude. We can modify gallery’s filter logic to exclude "I-Plant" when VarFilter is set to "ExcludeIPlant" and hence we can implement the exclusion logic by using the <> (not equal) operator inside your filter.
     
    With(
        {
            _Data: SortByColumns(
                Filter(
                    Permit_V2,
                    ('Permit Status' = "Approved" || 'Permit Status' = "Extended") &&
                    (
                        IsBlank(VarFilter) ||
                        ( VarFilter = "ExcludeIPlant" && 'Location of work' <> "I-Plant") ||
                        ( VarFilter <> "ExcludeIPlant" && 'Location of work' = VarFilter)
                    )
                ),
                "Created",
                SortOrder.Descending
            )
        },
        Filter(
            _Data,
            IsBlank(DatePicker1.SelectedDate) || DateValue(Dateofworktobedone) = DatePicker1.SelectedDate
        )
    )
    
     
     
     

     
     
    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!
     
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    The fundamental issue with adding either a conditional If() or Not <> statement directly to the data source is that neither are supported by Delegation, making the entire top filter not Delegable. They need to be included in the bottom "local" filter which then uses the output of the top Delegable With() statement. I have used @Valantis's excellent summary here and moved the filter down.
    With(
       {   _Data: 
          Filter(
             Permit_V2,
             'Permit Status' = "Approved" || 'Permit Status' = "Extended",
          )
       },
       Filter(
          _Data,
          IsBlank(DatePicker1.SelectedDate) || DateValue(Dateofworktobedone) = DatePicker1.SelectedDate,
          (VarExclude && 'Location of work' <> "I-Plant") ||
          (
             !VarExclude && 
             (IsBlank(VarFilter) || 'Location of work' = VarFilter)
          )
       )
    )
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • CU08060810-0 Profile Picture
    6 on at
    Hi @Valantis
    Thank you, the code you provided works well, but I'm still unsure of how to exclude more than one location. How do I add additional locations to this exclusion, like "I-Plant" along with "Halo" etc?
    If(VarExclude,'Location of work'<> "Halo",IsBlank(VarFilter)||'Location of work'=VarFilter)
     
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Just add it as below
    With(
       {   _Data: 
          Filter(
             Permit_V2,
             'Permit Status' = "Approved" || 'Permit Status' = "Extended",
          )
       },
       Filter(
          _Data,
          IsBlank(DatePicker1.SelectedDate) || DateValue(Dateofworktobedone) = DatePicker1.SelectedDate,
          (VarExclude && 'Location of work' <> "I-Plant" && 'Location of work' <> "Halo ") ||
          (
             !VarExclude && 
             (IsBlank(VarFilter) || 'Location of work' = VarFilter)
          )
       )
    )
     
  • Valantis Profile Picture
    6,735 on at

    Hi @CU08060810-0,

    Just wanted to check in and see if everything is working now. If you still need any help, feel free to let me know.

    Also, if the issue is resolved, it would be great if you could mark the answer as solved so others with the same question can find it easily.

     

    Thanks and have a great day!

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard