Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

'Last' Returning Old Data (Dataverse)

(0) ShareShare
ReportReport
Posted on by 402

Hi all,

 

I have a custom table in Dataverse and a Canvas App which is attempting to CountRows on the table. This is based in a Sandbox environment.

 

I saw this on the Power Apps Ideas pages which seems to indicate this is known behaviour. See also: CountRows function returning zero for DataVerse tables - Power Apps Canvas apps - Debajit's Power Ap.... I have now worked around this by using


CountIf (<Data Source>, true>)

 

However, I am now finding I have the same problem (of "out of date" data) again when trying to use 'Last' on the table. I want to get the value from a new record I have just patched to the table, but using Last is returning an 'out of date' data from a previous record on the table - hours later.

 

To hopefully make this easier to explain I've attached two screenshots. The first shows a Dataverse table that has records up to reference 'IO-09'. The second shows a very simple button in a Canvas App with OnSelect attempting to get the Last record in that table. Why is it returning an incorrect (out of date) value? At time of screenshots it was about 45 minutes since the two additional records, 08 and 09, were created, so it's not a 'lag' issue.


Further things I've tried, all of which did not make any difference:

1. I went to the Data pane in the Canvas App studio and 'refreshed' the Dataverse table connection.

2. I tried Refresh (Table Name) in the OnSelect on the button (per my diagram)

3. I tried setting the variable to Blank () before setting it with the 'Last' value (just to ensure the variable was truly blank/empty). 

4. I went to the table in Dataverse and added a new row directly in the table (as opposed to adding the rows by Patching from the Canvas App).

 

I cannot see any reason for this behaviour and also don't expect it to be linked to the 'caching' issue in Developer environments because how else are we expected to develop solutions in Sandbox environments and have them suitably work before moving them up to production?

 

Any help would be very much appreciated, thank you.

Categories:
  • pp365 Profile Picture
    402 on at
    Re: 'Last' Returning Old Data (Dataverse)

    Hi @Drrickryp ,

     

    Many thanks for getting back to me. For the benefit of anyone reading this thread in the future I think the context is found in the 'Delegation' section of the Learn documentation for 'Last', which says:

     

    When used with a data source, these functions can't be delegated. Only the first portion of the data source will be retrieved and then the function applied. The result may not represent the complete story. A warning may appear at authoring time to remind you of this limitation and to suggest switching to delegable alternatives where possible.
    
    For example, when used with a data source containing a large table with 1 million records, Last will be subject to the 
    non-delegation limit and will not return the last record of the entire data source. 

     

    Personally I think this is extremely unclear. When authoring in the Canvas App Studio there was no delegation warning (blue line/exclamation triangle). Additionally I was working with a table with ten rows - nothing like a million rows (significant for those aware of the "500 records limit in SharePoint"). I think a better job could be done here to alert App Makers of this issue when authoring in the App Studio as it would be better to return nothing or return a Delegation Warning, rather than partial data.

     

    Other resource of use is: 

    Connect to Microsoft Dataverse - Power Apps | Microsoft Learn

     

    Thank you @Drrickryp for your help in solving this!

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at
    Re: 'Last' Returning Old Data (Dataverse)

    @pp365

    Last() and Max() may be limited by delegation while First(Sort(...   never is. 

  • pp365 Profile Picture
    402 on at
    Re: 'Last' Returning Old Data (Dataverse)

    Hi @Drrickryp ,

     

    Many thanks for your solution which worked.

     

    However - I want to understand why it worked and why 'Last' didn't. With your solution my assumption is you're again forcing an action (Sort) and in so doing "refreshing" the data source. The question I have is, would 'Last' work in a Production instance of Dataverse - is this a limitation on the Sandbox instance - or is there some other reason that 'Last' did not work?

     

    Any context you can provide on this would be great - and thank you again for the solution (I'll mark as accepted in due course).

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at
    Re: 'Last' Returning Old Data (Dataverse)

    @pp365

    Use First(Sort(table, 'Created on', Descending)).Field

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,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard