cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
indhaa
Super User
Super User

No delegation warning but it is not delegable

Hi,

 

So I have removed the delegation warning on my code using the With Statement. However I found out now that it is not retrieving all the records. It is not delegable even though the warning is not there. Just tested this with 5 records to be sure.

 

indhaa_0-1651515051771.png

 

 

With ( {wFilterRecords: Filter(SP, 
       (ID=Value(IDFilterInput_2.Text) || IsBlank(IDFilterInput_2.Text)) &&
(FullName = NameFilterInput_2.Selected.DisplayName || IsBlank(NameFilterInput_2.Selected)))
    )},
 Switch(
        sortField,
        "Column1",
        Sort(wFilterRecords, "Column1", If(sortDirection,Ascending,Descending)),  
        "Column2", 
        Sort(wFilterRecords, "Column2", If(sortDirection,Ascending,Descending)) 
      ))

 

I tried like this too

 

With(
{wFilterRecords:SP},

SortByColumns( 
		Filter(
             wFilterRecords,
		(ID=Value(IDFilterInput_2.Text) || IsBlank(IDFilterInput_2.Text)) &&
	     (FullName = NameFilterInput_2.Selected.DisplayName || IsBlank(NameFilterInput_2.Selected)) 				
              ),sortField, If(sortDirection,Ascending,Descending)
     ))

 

 

 

7 REPLIES 7
Drrickryp
Super User
Super User

@indhaa 

Yep, that would be the expected behavior.  Kind of like disabling the bell in a fire alarm.  Doesn't prevent the fire. 

Yah. there are some posts given this as a solution. 

 

I thought my App was working and found it the hard way when it was not retrieving the latest records. So there is no way out of it, right. I have to use a collection?

Drrickryp
Super User
Super User

WarrenBelz
Super User
Super User

HI @indhaa 

and thanks for the blog tag @Drrickryp ,

The issue on the With() statement is that it is a "hidden" Delegation limitation and the Delegable filter in it still needs to return record numbers under your limit to get a complete set. In your case however you should be able to do this as this is the one occasion you can refer to fields dynamically.

SortByColumns(
   Filter(
      SP, 
      (
         ID = Value(IDFilterInput_2.Text) || 
         IsBlank(IDFilterInput_2.Text)
      ) &&
      (
         FullName = NameFilterInput_2.Selected.DisplayName || 
         IsBlank(NameFilterInput_2.Selected.DisplayName)
      )
   ),
   sortField,
   If(
      sortDirection,
      Ascending,
      Descending
   )
)

 

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.

Visit my blog Practical Power Apps

Hi @WarrenBelz 

 

Sorry but I didn't get what you meant above. Are you saying it will work for me with my current code?

 

My issue is the filter is not retrieving all the relevant records. I'm got a delegation error on the "sortField" variable which I was able to hide with With statement. Already my no of records is over 500. 

 

In the meantime I'm going over your blog !!

 

Hi @indhaa ,

My error with the SortByColumns being not Delegable with the Variable - I believed it was. Testing here confirms you are correct (as well an If or Switch statement in there also not being Delegable).

The issue is that your filter is otherwise Delegable and will return any number of records (100 at a time as you scroll though the gallery). Your variable sort field however is not, so cannot be used with this filter.

A With() statement collecting a Table with a Filter is really a (very) temporary collection and is subject to the same (and non-warning) Delegation limit. It is an extremely good tool for "Pre-filtering" when you can get the Delegable output under you limit and then use non-delegable queries on the result.

I think you may have to compromise with your filter if you want all of your records. You can of course use a single Sort on it.

 

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.

Visit my blog Practical Power Apps

 

Hi,

 

With() Statement is very useful. You can make your code small and I think it fetch the result much sooner too.

 

Since I have to use nested If too which is not delegable on the second If, I have to use Switch inside an If statement and remove the With() to make it delegable.

 

Thanks for your help @WarrenBelz @Drrickryp 

 

 

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (3,055)