cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
KimberlyM
Level 8

Delegation Warning on Second If Statement within Filter

Oh no! I thought I had this below code all figured out to get away from my delegation warnings (blue underlined). I totally forgot about how I am filtering for the user type (admin or not-admin). Admin sees all data while the not-admin will only see data that has their name associated with either the assigned to (AssignedTo) or member of (LeadMember) columns. 

Can anyone help me out with this. Month 4 of this problem. 

Sort(
   If(
      varAdmin,
      Filter(
         Lead_Data,
         If(
            SelectedStatus = "All",Or(Status.Value = "In Progress", Status.Value = "Not Started"),Status.Value = SelectedStatus
         )
      ),
      Filter(
         Lead_Data,
         AssignedTo.Value = varUser || LeadMember1.Value = varUser || LeadMember2.Value = varUser || LeadMember3.Value = varUser || LeadMember4.Value = varUser,
            If(
               SelectedStatus = "All",Or(Status.Value = "In Progress", Status.Value = "Not Started"),Status.Value = SelectedStatus
            )
         )
      ),
Created, Descending)

 

I do have a variable called "var1" that is loading the info now. 
How I thought I fixed it is with this code:
(I thought I fixed it because delegation warnings went away but I have no filters and no idea how to do a filter on this). I have var1 that loads different collections depending on button click and OnVisible of my dashboard screen.

Sort(var1, Created, Descending); 

 

 

Dashboard Screen OnVisible sees collection called: col_ActiveLeads
Button Press 1 OnSelect loads collection called: col_NotStarted

Button Press 2 OnSelect loads collection called: col_InProgress

Button Press 3 OnSelect loads collection called: col_DeadLead

Button Press 4 OnSelect loads collection called: col_CompletedDeal

Button Press 5 OnSelect loads collection called: col_ActiveLeads (same as OnVisible of Dashboard screen)

 

I hope this all makes sense.

3 REPLIES 3
Dual Super User
Dual Super User

Re: Delegation Warning on Second If Statement within Filter

The IF function is not a delegable function according to the delegation documentation. https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/delegation-overview. So using it in the innermost Filter() statement will give you delegation errors.  You can use an IF() to select a specific Filter to perform.  This makes your code longer but it should work.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Community Support Team
Community Support Team

Re: Delegation Warning on Second If Statement within Filter

Hi @KimberlyM ,

Currently, the If function could not be delegated within a Filter function. So when you use the If function within a Filter function, you would face a Delegation warning issue.

 

Is the amount of your Load_Data records more than 2000? If the amount of your Load_Data records is not more than 2000, you could ignore this warning issue.

More details about the Delegation in PowerApps, please check the following article:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/delegation-overview

 

In addition, please consider modify your formula as below:

Sort(
      Filter(
             Lead_Data,
             If(
                 varAdmin,
                 true,
                 AssignedTo.Value = varUser || LeadMember1.Value = varUser || LeadMember2.Value = varUser || LeadMember3.Value = varUser || LeadMember4.Value = varUser
             ),
             If(
                SelectedStatus = "All",
                Status.Value = "In Progress" || Status.Value = "Not Started",
                Status.Value = SelectedStatus
             )
      ),
      Created, 
      Descending
)

 

If the amount of your Load_Data records is more than 2000, you could consider bulk-load the data source records into a collection in your app, then use the collection as data source in your app instead of your original data source.

Please check and see if the alternative solution would help in your scenario:

https://powerusers.microsoft.com/t5/General-Discussion/Pulling-in-large-ish-SQL-tables/m-p/243777#M7...

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Dual Super User
Dual Super User

Re: Delegation Warning on Second If Statement within Filter

@KimberlyM 

 

I have blogged about a very similar scenario

https://www.youtube.com/watch?v=pn50AKn3Q1Y&list=PLTyFh-qDKAiE6ia-D94Qk5-AzpN4dqOmD&index=3

Start from 11 mins

 

--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,040)