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 / Using a Lookup to Incr...
Power Apps
Answered

Using a Lookup to Increment a value not working

(0) ShareShare
ReportReport
Posted on by 24

I have a model driven app with a embedded canvas app.

The canvas app has one gallery showing existing records in a table called (AFP Payment Schedules) based on a Job Number.

The second gallery I'm using with a collection to enable the user to input information and then I patch that into the AFP Payment Schedules table.

What I'm having a problem with is I'm trying to get last ID number (AFP Number) from the AFP Payment Schedules table, based on the Job Number and then increment ID by one. The second gallery should then be automatically listing the new line of info to be entered with the next AFP number after what already exists. The code I'm trying is below, but what I get returned each time is a zero. 

The existing AFP number is 1 so I'm expecting my new line in gallery two to be a 2 as its incremented 1 by 1.

 

Set(LastTotalAFP_ScheduleLines, LookUp('AFP Payment Schedules', 'Job Number' = [@ModelDrivenFormIntegration].Item.'Job Number').'AFP Number');
Set(TotalAFP_ScheduleLines, LastTotalAFP_ScheduleLines +1);
 
The collection then incorporates 
 AFPNumber: TotalAFP_ScheduleLines,
 

Thanks in advance for any help on this

David

Categories:
I have the same question (0)
  • Verified answer
    v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @dgarrick ,

     

    Please try this:

    Set(
     LastTotalAFP_ScheduleLines, 
     First(
     Sort(
     Filter(
     'AFP Payment Schedules', 
     'Job Number' = [@ModelDrivenFormIntegration].Item.'Job Number'
     ),
     'AFP Number', 
     SortOrder.Descending
     )
     ).'AFP Number'
    );
    Set(TotalAFP_ScheduleLines, LastTotalAFP_ScheduleLines +1);

     

    Best regards,

  • dgarrick Profile Picture
    24 on at

    That worked perfectly, thank you.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 531 Most Valuable Professional

#2
Haque Profile Picture

Haque 261

#3
Kalathiya Profile Picture

Kalathiya 221 Super User 2026 Season 1

Last 30 days Overall leaderboard