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. 🙂
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.
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.
User | Count |
---|---|
261 | |
129 | |
99 | |
48 | |
47 |