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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filtering a gallery fo...
Power Apps
Unanswered

Filtering a gallery for all records vs. user records using a button

(1) ShareShare
ReportReport
Posted on by 155

I'm having trouble understanding how to filter a gallery for all records vs. just the user records by using a button.  A caveat is that my gallery offers a dropdown box so users can choose one of 40 locations to filter by. The gallery's Items property is shown below, which is time-limited to avoid delegation problems (thanks to @Amik.) Is it feasible to add a button on screen to "View Only My Requests"? Or some other solution? (In the case of a button, there would be no location needed so the dropdown box would remain unselected.)  It's ok if a solution restricts user records to 60 days as well, if that makes an easier formula.


With(
    {
        _previous_60_days: DateAdd(
            Now(),
            -60,
            TimeUnit.Days
        )
    },
    With(
        {
            _pre_filtered_data: Filter(
                'New Service Request List',
                Created >= _previous_60_days
            )
        },
        Filter(
            _pre_filtered_data,
            Len(Dropdown1.Selected.Value) = 0 || Dropdown1.Selected.Value in 'Site/Supervisor'.Value
        )
    )
)

 

 

Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,351 Super User 2025 Season 2 on at

    Hi @OneWinPlease 

     

    If you have a Field that exists like an owner having the email or something

     

    Just wrap your entire with, with a with.. Wow I actually typed that.

    UGGGG I deleted my code snipper gtrr

     

    The below uses a button to toggle show yours and show all. The words ON the label is what it WILL be if you click it not what it is currently

     

    In your Items, the switch just either uses your current code, or filters your current code based on an Email column I assumed you have.

     

     

    Using a button
    
    Screen.OnVisible 
    Set(_buttonLabel, "Show Mine Only"); // This means its CURRENTLY showing all
    
    On your button (and you can do dropdowns whatever, you asked about buttons)
    
    Set the Button Text to
    _buttonLabel
    
    Set the Button OnSelect
    
    If(_buttonLabel = "Show Mine Only", 
     Set(_buttonLabel,"Show All), 
     Set(_buttonLabel, "Show Mine Only")
    );
    
    Your Items Property
    
    Switch(_buttonLabel,
     "Show Mine Only", // its currently showing all
     Copy and Paste your stuff here
     );
     ,
     "Show All", // means its showing JUST yours. remember clicking the button swap its
     With(
     { MyData: 
     Copy and Paste your stuff here
     },
    
     Filter(MyData, Email = User().Email);
     );
    ); 
    

     

     

     


    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

  • Ami K Profile Picture
    15,679 Super User 2024 Season 1 on at

    @OneWinPlease - consider leveraging Local Context Variables here:

     

    1. On the OnSelect property of your Dropdown/Combobox control, use:

     

    UpdateContext({ctx_all: false})

     

    2. On the OnSelect property of your Button control, use:

     

    UpdateContext({ctx_all: true});
    Reset(Dropdown1)

     

    3. On the OnVisible property of your Screen, use:

     

    UpdateContext({ctx_all: false})

     

    4. Revise the Items property of your Gallery control to:

     

    With(
     {
     _previous_30_days: DateAdd(
     Now(),
     -60,
     TimeUnit.Days
     )
     },
     With(
     {
     _pre_filtered_data: Filter(
     'New Service Request List',
     Created >= _previous_60_days
     )
     },
     Filter(
     _pre_filtered_data,
     Len(Dropdown1.Selected.Value) = 0 || ctx_all || Dropdown1.Selected.Value in 'Site/Supervisor'.Value,
     !ctx_all || 'Your People Field'.Email = User().Email
     )
     )
    )

     

    Notes:

     

    • The above assumes you want to filter by a People data type in your list (e.g. the Created By field)
    • For a ComboBox control, the DefaultSelectedItems property should be blank.
    • For a Dropdown control, the Default property should be blank and the AllowEmptySelection property should be set to true.
  • OneWinPlease Profile Picture
    155 on at

    @Amik   - thanks, I followed your suggestions, though when I press the My Items button, the gallery goes blank.  In other words, no records show.

  • Ami K Profile Picture
    15,679 Super User 2024 Season 1 on at

    @OneWinPlease - could you please share your code (in text).

  • OneWinPlease Profile Picture
    155 on at

    @Amik :

     

    My Items button, OnSelect: 

    UpdateContext({ctx_all: true});
    Reset(Dropdown1)
     
    Dropdown box (not combo) OnSelect:
    UpdateContext({ctx_all: false})
     
    Screen OnVisible property:
    UpdateContext({ctx_all: false})
     
    Gallery's Items property, was 60 days but I changed it to 30:
    With(
        {
            _previous_30_days: DateAdd(
                Now(),
                -30,
                TimeUnit.Days
            )
        },
        With(
            {
                _pre_filtered_data: Filter(
                    'New Service Request List',
                    Created >= _previous_30_days
                )
            },
            Filter(
                _pre_filtered_data,
                Len(Dropdown1.Selected.Value) = 0 || ctx_all || Dropdown1.Selected.Value in 'Site/Supervisor'.Value,
                !ctx_all || 'Created By'.Email = User().Email
            )
        )
    )
  • Ami K Profile Picture
    15,679 Super User 2024 Season 1 on at

    @OneWinPlease - what do you have in the Default property of that Dropdown control?

  • OneWinPlease Profile Picture
    155 on at

    @Amik  - It is blank, no formula.

  • Ami K Profile Picture
    15,679 Super User 2024 Season 1 on at

    @OneWinPlease - not something I am able to reproduce in my environment.

     

    Could you replace this line:

     

    !ctx_all || 'Created By'.Email = User().Email

     

    With something else like:

     

    !ctx_all || ID = 5

     

    I want to identify if it is that People field which is causing the Table to return blank.

     

  • OneWinPlease Profile Picture
    155 on at

    @Amik  -  I tried that (and other ID #s just in case 5 was deleted in my list).   Same thing happened; I press the "My Items" button and the gallery goes blank.  I want to make sure I was clear: the gallery starts by showing all tickets. The My Items button would remove any location part of the filter and just show the user's items, which is non-location based. I'm wondering if that's too complex an action.

     

    Maybe I should start with the gallery showing only the user's tickets, and then move into the location based filter? Would that be easier? I don't know enough (yet) about context variables to determine how to change up the formulas, I'm afraid. Right now, I have 2 separate screens (My items, and All Items) that avoid this entire issue, but I'm concerned about having too many screens (performance concerns) and had hoped to combine the My and All items screens. (I also have welcome and success screens, so that makes 6 screens total with a lot of fields.)

  • Ami K Profile Picture
    15,679 Super User 2024 Season 1 on at

    @OneWinPlease - I have replicated the solution in my environment and unfortunately I still cannot see anything which would obviously return blank in your Gallery control.

     

    I note @FLMike has also responded here so worth checking if his solution achieves what you need. If not, I will add another super user who might notice something obvious. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard