Calc - add cell next to last non empty cell of a column

I have a budgeting spreadsheet where column C is the account balance after that transaction and column D is either a check mark or “pending” or blank. (it’s for if the payment has cleared)

What I want to is find the amount for the balance after the last cleared payment

is this even possible?

Please upload an example file.

AI says :