Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Want to use MAX not LAST

In a form for viewing or entering records to an Excel sheet, I have successfully used the following for adding a new record, adding 1 to the EmployeeID of the last record:

If(EditForm1.Mode=FormMode.New, Last(LikeVideo).EmployeeID+1, ThisItem.EmployeeID)

But since the last record may not be contain the max value in that field, I decided to use MAX function.  I tried all of the following, with no success:

If(EditForm1.Mode=FormMode.New, Max(LikeVideo.EmployeeID)+1, ThisItem.EmployeeID)

If(EditForm1.Mode=FormMode.New, Max(EmployeeID)+1, ThisItem.EmployeeID)

I even tried (which I rightly did not think would work):

If(EditForm1.Mode=FormMode.New, Max(LikeVideo).EmployeeID+1, ThisItem.EmployeeID)


Max seems to be a valid function, but I am out of ideas.  Help!  I'm sure it is simple, but as we all know, everything in computers is easy, but often not intuitive. 🙂 

Super User
Super User

Try using Sort on the table to ensure your IDs are in order, then use First or Last as appropriate to pick the one you want.

Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.
Super User
Super User


I suggest using First(Sort(LikeVideo,EmployeeID,Descending)).EmployeeID+1.  Make sure that EmployeeID is a number type column. Max() and Last() are not delegatable, meaning that once you exceed the maximum number of items (500 default, 2000 maximum), the result will not be correct.

Helpful resources

Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (5,008)