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

Notifications

Announcements

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

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
    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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard