PO balance tracking with sharepoint using power automate
I have created a Power App to add or edit items in a SharePoint list. Here, I want to do two things, which were confusing for me, and hopefully could be done flow.
The SharePoint list is for tracking the POs and Invoices. In the case of partial deliveries, there will be multiple invoices for the same PO (Simple example given in the below picture). In this case, I want to do the following:
1. Compare the multiple invoice lines for the same PO and return what is the balance amount. (PO amount - Total Invoice amount)
2. Duplicate the same line item automatically (if the PO amount is greater than the total invoice amount).
If there is a better solution for the above problem, please feel free to advise me.
And if you need any clarification please let me know.