web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Last function doesnt w...
Power Apps
Unanswered

Last function doesnt work correct

(0) ShareShare
ReportReport
Posted on by 35

Hey..

I use the LAST function in order to bring information from the Dataverse table and according to the information received to update information in the Form itself.
In the specific case I take a numerical value that is a type of Counter for me and increase it by one.

The problem is that the Last function does not work well and does not bring me the last record according to the parameters I defined.
After a test I did it seems that this problem is known and manipulations are needed for it to really work.

I would appreciate help on this matter, it is very critical to the system I am developing and such a backward change will result in a long and unnecessary development time.

Thanks.

Here is a picture of the code I wrote down, the picture shows both the code before the change that doesn't work and the code after the change

Screenshot 2023-08-27 102507.png
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    156,027 Most Valuable Professional on at

    Hi @Mordechay ,

    Please try this alternate approach

    If(
     IsBlank(ThisItem.RW_Flag),
     LookUp(
     Sort(
     Intg_PIBS,
     Row_ID,
     SortOrder.Descending
     ),
     SystemID = varSystem && 
     AOH_ID = varAOHID &&
     Test_Type = Dropdown5.Selected.Value
     ).RW_Flag + 1, 
     Thisltem.RW_Flag
    )

     

    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

  • Mordechay Profile Picture
    35 on at

    Thanks for the response,

    I'm not looking for an alternative to the code I wrote. The code in the second configuration with Sort works and brings the desired result.

    I'm trying to understand why using the Last function doesn't work as it should, I use this function quite a bit and it's a bit disturbing to see that it doesn't work well

  • WarrenBelz Profile Picture
    156,027 Most Valuable Professional on at

    @Mordechay ,

    I never use Last() - instead I sort in reverse and use First() which always works. Also LookUp() finds the first matching record to the criteria stated, so does the same thing and returns a single record - the same as First(Filter( .  .))

     

    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

  • Mordechay Profile Picture
    35 on at

    @WarrenBelz 

    Why would First work but Last wouldn't?
    I didn't understand what you were saying about the second code I wrote with Sort, would you also change it?

  • WarrenBelz Profile Picture
    156,027 Most Valuable Professional on at

    @Mordechay,

    It was an alternate structure that I believed would achieve your required result. Using First() with the data sorted in the reverse is the same as using Last with the data sorted "normally".  To more closely reflect your code posted, but using this principle

    If(
     IsBlank(ThisItem.RW_Flag),
     First(
     Filter(
     Sort(
     Intg_PIBS,
     Row_ID,
     SortOrder.Descending
     ),
     SystemID = varSystem && 
     AOH_ID = varAOHID &&
     Test_Type = Dropdown5.Selected.Value
     )
     ).RW_Flag + 1, 
     Thisltem.RW_Flag
    )

    However, to more accurately answer your question - Last is not Delegable (see this Delegable functions guide) - whereas First and Lookup are (refer here).

     

    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

     

  • Mordechay Profile Picture
    35 on at

    @WarrenBelz 

    If I understand correctly, both Last and First both have a sensitivity to delegation. But in the way you suggest that we first arrange the table as we want, then the record we want will be the first and that's how we overcome this problem?

    Of course, this comes from the understanding that filter and sort are not sensitive to delegation

  • WarrenBelz Profile Picture
    156,027 Most Valuable Professional on at

    Hi @Mordechay ,

    Yes, Filter and Sort are in themselves Delegable. First is listed as Delegable and is by default anyway as the record returned will always be within your limit. Sorting in the order required will simply place the required record at the start of the data set allowing First or a filtered LookUp.to select 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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 324 Most Valuable Professional

#2
11manish Profile Picture

11manish 193

#3
Valantis Profile Picture

Valantis 138

Last 30 days Overall leaderboard