Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building 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
        )
    )
)

 

 

  • WarrenBelz Profile Picture
    146,695 Most Valuable Professional on at
    Re: Filtering a gallery for all records vs. user records using a button

    Hi @OneWinPlease ,

    If the button toggles the variable, yes it will switch between the two filters.

  • OneWinPlease Profile Picture
    155 on at
    Re: Filtering a gallery for all records vs. user records using a button

    @WarrenBelz thank you. I'll take a look at that after I finish my other assignment. Honestly, your and @Amik's formulas were good, I believe. What solved my problem late yesterday: I increased my delegation limit to 2000 (it was at 500) and the 30 day time frame started showing the recent data needed. There were no delegation warnings, which, being new at this, threw me off. 

     

    When I go back later to try your solutions again: Does the update context variable and function allow the "See Only My Items" button to toggle? Once you hit "See Only Mine" how would the user get back to "See All"?

  • WarrenBelz Profile Picture
    146,695 Most Valuable Professional on at
    Re: Filtering a gallery for all records vs. user records using a button

    Hi @OneWinPlease ,

    If this is a Delegation issue, (I assume you are using SharePoint) try

    With(
     {
     _previous_30_days: 
     DateAdd(
     Now(),
     -30,
     TimeUnit.Days
     ),
     _pre_filtered_data:
     Sort(
     'New Service Request List',
     Created,
     SortOrder.Descending
     )
     },
     Filter(
     _pre_filtered_data,
     Created >= _previous_30_days &&
     (
     ctx_all &&
     (
     Len(Dropdown1.Selected.Value) = 0 ||
     Dropdown1.Selected.Value in 'Site/Supervisor'.Value
     )
     ) ||
     (
     !ctx_all && 
     'Created By'.Email = User().Email
     )
     )
    )

     

    Please click Accept as solution 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 giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • OneWinPlease Profile Picture
    155 on at
    Re: Filtering a gallery for all records vs. user records using a button

    @Amik  and @WarrenBelz : Post-reply light bulb moment: I just changed the date criteria of the formulas to 10 days and can now see July (most recent) data. I must have been hitting my delegation limit without getting a warning. I'll need to filter by less than 30 days it seems.  Delegation isn't what this particular post was about, but it ended up causing an issue. If I can come back to this assignment I will endeavor the button toggle context variable and I bet it will work. 

  • OneWinPlease Profile Picture
    155 on at
    Re: Filtering a gallery for all records vs. user records using a button

    @WarrenBelz  - thank you, it works similarly to the solution from @Amik, but for some crazy reason only returns help desk tickets through end of June. Same issue. I'm wondering if my app is just a buggy combo of  modern and classic gone awry, since I had turned modern controls on and then off again a couple times. It's entirely possible there's something buggy with the SharePoint list itself, having been imported ages ago (not by me) from Infopath, ancient and incorrect settings and all. I hate to give up, but unfortunately time has run out for me to work on this. I've left the gallery in a second-best view of all tickets in the last 30 days, but not by (dropdown or combo box) location. This seems to avoid the delegation warning. Folks are just going to have to scroll.  Thanks everyone for your dedication! 

  • WarrenBelz Profile Picture
    146,695 Most Valuable Professional on at
    Re: Filtering a gallery for all records vs. user records using a button

    Thanks @Amik ,

    @OneWinPlease ,

    Try this format - I tend to use bracketing a bit more as it is easier to follow

    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,
     (
     ctx_all &&
     (
     Len(Dropdown1.Selected.Value) = 0 ||
     Dropdown1.Selected.Value in 'Site/Supervisor'.Value
     )
     ) ||
     (
     !ctx_all && 
     'Created By'.Email = User().Email
     )
     )
     )
    )

     

    Please click Accept as solution 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 giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Ami K Profile Picture
    15,665 Super User 2024 Season 1 on at
    Re: Filtering a gallery for all records vs. user records using a button

    @OneWinPlease - subject to his availability I would defer to @WarrenBelz who might be able to provide better advice.

  • OneWinPlease Profile Picture
    155 on at
    Re: Filtering a gallery for all records vs. user records using a button

    @Amik , for various reasons, I have to step away from this project and will be unable to try @FLMike 's solution. But I have been asked to fix one thing. The code you provided for me earlier, I just noticed, does not show help desk tickets beyond the end of June.  I was reading online about the Time aspect of a date and time column sometimes causing issues. The problem now is, my Created column does not allow just the date.  It offers either Standard or Friendly format, but that's it. (It's set to Standard.)  I'm looking at site column definitions and the like, but do you know of a workaround in the formula that would address this?

    (Edited to say, I just used JSON to change the Created column to Date only in xx/xx/xxxx format. I thought it might help but it did not seem to, so far.)

     

    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
            )
        )
    )
  • OneWinPlease Profile Picture
    155 on at
    Re: Filtering a gallery for all records vs. user records using a button

    Ok, thanks for trying so diligently, @Amik. I was going to try the solution from @FLMike next, after the weekend here in the US. 

  • Ami K Profile Picture
    15,665 Super User 2024 Season 1 on at
    Re: Filtering a gallery for all records vs. user records using a button

    @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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,695 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard