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 / Update balance leave r...
Power Apps
Unanswered

Update balance leave request

(0) ShareShare
ReportReport
Posted on by 122

Hi

I'm building a leave request application using PowerApps for Teams. Here, the users from a Office365Users work group can make their requests and a manager can review and approve or reject them.

 

The app is almost complete, I have a table that records all the requests, and each request has a field "TimeRequested" that records how much time is being requested (using hours in this example).

 

The last thing I need to do (I'm struggling with that) is to record how many hours each user has remaining: I think I would need a new table for that ("LeaveBalance"), with at least a field for the user name or email, and a "TimeRemaining" field.

 

The image below shows the manager page with all the pending requests: when the manager clicks on the green button, that request status is updated to "Approved", and to "Rejected" by clicking the red button (those are choice values on the request table). That change occurs only on the selected request (that's why all pending requests have those buttons).

 

What I would like to do is, when pressing the "Approved" button, the "TimeRequested" value of that request would subtract to the "TimeRemaining" of the "LeaveBalance" table. Also, the formula should also speficy which user is making the request so it can subtract to the correct user on "LeaveBalance".

 

Any idea how can I achieve this? Please tell me if I need to clarify something.

Thank you

Pedro Fernandes
64564536456456.png

Categories:
  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

    Where does your app get the initial leave balance for your employees?

  • PedroFernandes Profile Picture
    122 on at

    That's something I still need to implement: I could add a field like "InicialLeaveTime" on the "LeaveBalance" table.

    But since that inicial value would change from the moment the first request is approved, wouldn't be simpler to manually add that value to the "TimeRemaining" field when the entry for an user is created?

  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

    The way I read your post, you don't currently have a Time Remaining field?

     

    If you have not already calculated the number of days, you will need to do that.   Then on approve you would patch your inicial value or time remaining, whichever you are going to use:

     

    Patch(datasource, {incialvalue: incialvalue - number of days}

     

     

  • PedroFernandes Profile Picture
    122 on at

    Meanwhile I created that field and gave it a number value (176, in this case),

    My formula is something like this (some names are translated to english):

    Patch(LeaveBalance, 
     
     {
     User: ThisItem.'Created By',
     TimeRemaining: TimeRemaining - tempVar2
     }
    )

     

    Note: tempVer2 is a local variable that stores the "TimeRequested" of that specific request.

    I get an error on that last line of code, saying the name isn't valid, the identifier isn't recognized (error points to the second time "TimeRemaining" is written on that line)

  • JR-BejeweledOne Profile Picture
    5,836 Moderator on at

    Since it appears that this is a newly created record that won't have any data in the record, you will need to capture the beginning balance and subtract the tempVar2 from that the first time you create this record.   After that you can update the record. 

     

    Try this: Replace beginning balance with the information you captured.

    Patch(LeaveBalance, 
     
     {
     User: ThisItem.'Created By',
     TimeRemaining: BeginningBalance - tempVar2
     }
    )

     

     

  • elvinvaz Profile Picture
    9 on at

    you need to create a clearcollect formula check this video I built mine thanks to him. 
    https://www.youtube.com/watch?v=wS3-Ed5lkxY

  • elvinvaz Profile Picture
    9 on at

    Sorry the video is long but around time 1hr:12

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 258

#3
Mohsin Ali Profile Picture

Mohsin Ali 231

Last 30 days Overall leaderboard