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 / Patch lookup with FirstN
Power Apps
Answered

Patch lookup with FirstN

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I am trying to patch a record in a sharepoint list.

The logic is if there is a record existing already with the status as pending then it updates the record

If there is not a record with a status pending then it creates a new record

 

However i need to update the display flag for the record with the approved status so the app displays the latest change and calculations can be run on the data.

If(LookUp(Forecast, CustId=Gallery2.Selected.CustId && Approved="Pending",true)=true
,Patch(Forecast, LookUp(Forecast,Title=Gallery2.Selected.TitleText.Text),
{ '1-April':Value(AprilInput.Text),
 '2-May':Value(MayInput.Text), 
 '3-June':Value(JunInput.Text), 
 '4-Jul':Value(JulInput.Text), 
 '5-Aug':Value(AugInput.Text), 
 '6-Sep':Value(SepInput.Text), 
 '7-Oct':Value(OctInput.Text), 
 '8-Nov':Value(NovInput.Text), 
 '9-Dec':Value(DecInput.Text),
 '10-Jan':Value(JanInput.Text),
 '11-Feb':Value(FebInput.Text),
 '12-Mar':Value(MarInput.Text),
 New:1,
 PendingDisplay:1 })


,
Collect(Forecast,{CustId:Gallery2.Selected.CustId, 
 '1-April':Value(AprilInput.Text),
 '2-May':Value(MayInput.Text), 
 '3-June':Value(JunInput.Text), 
 '4-Jul':Value(JulInput.Text), 
 '5-Aug':Value(AugInput.Text), 
 '6-Sep':Value(SepInput.Text), 
 '7-Oct':Value(OctInput.Text), 
 '8-Nov':Value(NovInput.Text), 
 '9-Dec':Value(DecInput.Text),
 '10-Jan':Value(JanInput.Text),
 '11-Feb':Value(FebInput.Text),
 '12-Mar':Value(MarInput.Text),
 DateAdded: Now(),
 Display:0,
 New:1,
 PendingDisplay:1

 ,Title: Gallery2.Selected.CustId&Text(Now())
 }));

 Patch(Forecast, First(FirstN(Sort(LookUp(Forecast, CustId=Gallery2.Selected.CustId && PendingDisplay = 1),DateAdded , Ascending),1)),{PendingDisplay:0})

The first Patch and collect work fine but i am having difficulty with the last patch - the sort is invalid - what have i done wrong?

Categories:
I have the same question (0)
  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    worked it out and changed the lookup to a filter:

    Patch(Forecast, First(FirstN(Sort(Filter(Forecast,CustId=Gallery2.Selected.CustId && PendingDisplay=1), DateAdded , Ascending),1)),{PendingDisplay:0})

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard