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 / With()-function no lon...
Power Apps
Unanswered

With()-function no longer delegable

(4) ShareShare
ReportReport
Posted on by 8
As of yesterday, the With()-function does not delegate properly to neither Dataverse nor SharePoint when using LookUp(), filtering on StartsWith() etc for powerapps authoring version 3.25042.10.
I've always relied on this method and leaned into it heavily for optimization, maintainability and readability purposes.

The case where i first bumped into it was yesterday, when i was trying to do a "Duplicate Item"-button with autonumbering, using the same method i always have:
 
With(
    {
        _text: Text($"{Gallery.Selected.SingleLineOfText} - Copy (")
    },
    Patch(List, Defaults('List'),
        {
            Column1: Gallery.Selected.Column1,
            Column2: Gallery.Selected.Column2,
            SingleLineOfText: $"{_text}{CountRows(Filter(List, StartsWith(SingleLineOfText, _text))) + 1})"
        }
    )
)
 

This now throws a delegation warning: "The 'StartsWith' function cannot be delegated if a field name appears in the second argument."
Effectively what has happened is that anything that is defined within the With()-scope is treated as a dynamic value.
This also mean that using With() to optimize lookups when doing a ForAll() through a list with complex relationships, even if typed using ID:s in a number column, will no longer function properly.
For instance doing the following lookup will no longer delegate:
 
ForAll(List As _row,
    With(
        {
            _lookup: LookUp(OtherList, ID = _row.OtherListID)
        },
        UpdateIf(List, Column1 = Blank(), Column1: _lookup.Column1})
    )
)
 
I've searched for any documentation relating to this and cannot find anything about the change, i also cannot find anyone posting about it online yet, but it has a significant impact on how apps are built on a higher level and the workarounds to resolve this completely bloat the scope of variables and collections required to do the same operations.
To work around this, you would now instead have to create collections with these references and read them back into the app, which is basically impossible in some cases, as many devices these apps have to run on simply cannot deal with the amount of rows stored in collections this would require, compared to a block scoped variable contained within a With()-function that basically cleans itself up once the operation is complete.

Are there any known solutions to this? Does anyone know why this changed?

Edit: Found an obvious, but nasty, workaround. If you do the following it works:
ForAll(List As _row,
    With(
        {
            _lookup: LookUp(OtherList, ID = _row.OtherListID)
        },
        With(
            {
                _column1: _lookup.Column1
            },
            UpdateIf(List, Column1 = Blank(), Column1: _column1 })
        )
    )
)
Still the question is why this changed just yesterday? Before 12:00 UTC+1 this worked, later in the afternoon the same code that previously work didn't (In multiple apps.).
Categories:
I have the same question (0)
  • stampcoin Profile Picture
    5,058 Super User 2025 Season 2 on at
    As I understand it should be CountRow.
     
    and
    Count, CountA, CountIf, and CountRows functions  also has some important note.
     

    Enjoy Power Platform and have a great day 🚀 |  My LinkedIn

    If the answer helps, please consider 👍, Thanks.

  • Michael E. Gernaey Profile Picture
    53,452 Super User 2025 Season 2 on at
     
    With isn't about delegation, its about scope. You are using (as @stampcoin) mentioned CountRows, which is absolutely not delegatable and therfore whatever you are doing is not delegatable.
     
    What I would like to see is not the expresssion
     
    I want to see the expressions in your code, with the squiggles under the words and then the exact error it says, which I do not see in your post.
  • JR-25041131-0 Profile Picture
    8 on at
    @Michael E. Gernaey @stampcoin
     
    Even if i do this on a gallery, it's not delegable anymore, it's NOT the CountRows (Read the provided delegation warning in OP.):
    With(
      {
        _text: Text($"{Gallery.Selected.SingleLineOfText} - Copy (")
      },
      Filter(List, StartsWith(SingleLineOfText, _text)
    )
    This is a new behaviour since about lunch time 04-25 UTC+1, I'm aware of how delegation the With() function could obfuscate delegation warnings (These where always visible in the live monitor however.).
     
    The following isn't delegable anymore either:

    (Ignore the fact that the LookUp in this case is unnecessary as the _patch contains the return value.)
    With(
      {
        _patch: Patch(List, Defaults(List), { Column: "Some value" })
      },
      Set(gblItem, LookUp(List, ID = _patch.ID))
    )
    However, this still delegates:

    With(
      {
        _patch: Patch(List, Defaults(List), { Column: "Some value" }).ID
      },
      Set(gblItem, LookUp(List, ID = _patch))
    )
     
    This is across 4 different tenants, multiple environments in each, changing the authoring version of power apps has no effect.

    It seems to treat the block scoped variable as a dynamic field rather than a static type if the value is fetched from a data source (SP list or Dataverse doesn't matter, delegation is broken for both.).
  • stampcoin Profile Picture
    5,058 Super User 2025 Season 2 on at
     
    I tried your code in two env, same authoring version 3.25042.10
     
    With(
      {
        _patch: Patch(List, Defaults(List), { Column: "Some value" }).ID
      },
      Set(gblItem, LookUp(List, ID = _patch))
    ),
     
    I didn't get the warning, hope this give your some leads
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    I will throw in a comment here as I use With() extensively and have done so for quite some time. With() does nothing more than set a (very) temporary variable able to be referenced throughout anything inside With( . . . ). I have however found some isolated incidents where the usage inside a complex function produces a delegation error (it seems Power Apps cannot "catch up") - in your case you are using it in a StartsWith statement inside a Filter inside a CountRows statement in a Table. The second one is inside a Lookup inside a ForAll. I totally agree both should technically work.
    As an experiment on the first one - see if this works
    UpdateContext({varText: Text($"{Gallery.Selected.SingleLineOfText} - Copy (")});
    Patch(
       List, 
       Defaults('List'),
       {
          Column1: Gallery.Selected.Column1,
          Column2: Gallery.Selected.Column2,
          SingleLineOfText: $"{varText}{CountRows(Filter(List, StartsWith(SingleLineOfText, varText))) + 1})"
       }
    )
     
  • JR-25041131-0 Profile Picture
    8 on at
    @WarrenBelz

    Yes, as i mentioned it seems the definitions of the variables in With() has changed. While I am fully aware that With() merely creates block scoped variables that lives for the runtime duration of the function, suddenly it treats Text($"{Gallery.Selected.SingleLineOfText} - Copy (") as a "field name", hinting that it retains the context of the relationship with the data source and thus treats it as a dynamic value rather than converting to a static type as expected.
    This is not the only example where this is happening, I have lots of code that worked previously that suddenly stopped delegating, I have validated that the delegation was previously functioning through the live monitor tool.

    Using UpdateContext() and Set() solves the delegation warning as it properly redefines the type from a dynamic to a static value, but it's also not possible to do in the case of ForAll()-optimizations, where you could block scope a lookup and then reference it multiple times by dot notation. You also cannot use the ID from this lookup to do another lookup, despite the field values being of matching types (Again it will say the lookup cannot delegate due to a field name being present in the second argument.).

    If this had been in a single environment, or even a single tenant, I wouldn't have been too surprised, but I'm seeing this behaviour across multiple tenants (In default, dev and prod environments, none with "Get features early".).
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    Looking again at the first piece of code you posted, I get this error (which is actually expected)
    You cannot use ForAll on a Data source to write back to the same data source. You are also always going to have some Delegation limitation here with ForAll, however if List (or the sample you want to update) is less than 2,000 items, you can do this
    With(
       {_Data: List},
       ForAll(
          _Data As _row,
          With(
             {
                _lookup: 
                LookUp(
                   OtherList, 
                   ID = _row.OtherListID
                )
             },
             Patch(
                List,
                {
                   Column1: 
                   Coalesce(
                      _row.Column1,
                      _lookup.Column1
                   )
                }
             )
          )
       )
    )
     
    Please click 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 giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn   
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for or if you need further assistance.

    Please click 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 giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn   
  • JR-25041131-0 Profile Picture
    8 on at
    @WarrenBelz Sadly no, the code snippet you pointed out was pseudo code where i simply forgot to properly type out the references.
    However, from the response code you provided, if the Patch() did a LookUp() like: Patch(List, LookUp(List, ID = _lookup.ParentID), { Column1: Coalesce(_row.Column1, _lookup.Column1) })
    The LookUp() inside the patch would now be non-delegable, because even if _lookup.ParentID is a number column, it will fail the type check with the same error: "The LookUp function cannot be delegated if a field value appears in the second argument".

    I'm very well aware that With() is just intended to be for block scoping, it's also the entire reason i work with it so often to reduce variable / collection overhead in my apps where it isn't necessary, my point is that how these variables resolve field values has recently changed behaviour across multiple tenants and environments (Also verified by coworkers.).
    As i cannot post my code publicly without obfuscating it and my attempts to do so have been poor that i've been misunderstood, i'll try to explain a common scenario and how it differs instead:

    Applying a With() to block scope a filtered down list where i can then do a ForAll() over the filtered list.
    Inside this I check for a condition and if the condition is met i run another With() block to do a lookup / filter, because i might need to copy several values of a related record or do some math operations. From this point i used to be able to write these values back into the original record by referencing my block scoped LookUp() inside the With()-function by using dot notation to access different columns. This has always been delegable previously (As long as your lookup/filter follows delegation limitations.), however this has now changed.
    Trying to write a single line of text value from the LookUp() inside the condition of the ForAll back to the data source now throws a delegation warning, because accessing the columns by dot notation throws warnings that a column of the type single line of text does not expect a field value and may be non-delegable.

    This implies that the LookUp() inside the With() creates a direct reference to the original data source, making the type of the columns "field values", rather than an object with type defined key-value pairs mirroring the original (I'm aware it always hid additional metadata like the etags under the hood.).
    IF you define the LookUp() using dot notation directly in the With()-function however, the reference resolves to it's expected type indicating that there's some mismatch in how the field values are resolved.
    This can in some cases be worked around by adding a nested With(), similarly to the following pseudo code: With({ _loookup: LookUp() }, With({ _col1: _lookup.col1, _col2: _lookup.col2 }, <Data operations using _col1 and _col2 goes here> ))
    However this would not properly resolve the type definitions and cause delegation warnings: With({ _loookup: LookUp() }, <Data operations using _lookup.col1 and _lookup.col2 goes here> )

    This was not an issue 2 weeks ago, as the dot notation resolved the type automatically (Manually converting using Text(), Value() or GUID() does not work either.).
    I have previously verified the delegation as fully functional both by using the live monitoring tool and by having it filter data sources containing far more records than the row limits of non-delegable filters.
    This suggests that something in how the data is stored and referenced inside powerapps has changed, probably due to optimizing the advanced analysis engine, but some edge case in the With()-function has caused it to no longer resolve the proper type definitions in certain scenarios.
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    Yes - I agree with all you have posted - it should technically work and the main area difficult to work around (if it does not work) is usage inside ForAll as this is the only way of declaring a Variable in there. There is however a growing list of bugs in the latest releases - have you tried reverting the Authoring Version ?

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 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard