I was attempting to explain the rules using an example but clearly that didn't do it
The ranks are pre-defined. Table 1 shows transactions for a given month (Jan 2019). Table 2 has payments received in subsequent months (Feb-April 2019), these payments should be applied each month to the balances in Table 1 but in the order of the rank specified.
So, in this example, payment amounts received should offset the balances in column TxnTypeA first, and within that column, in the order of increasing rank. Once all of TxnTypeA has been paid off, then the same logic should be followed on the next column TxnTypeB, again in the order of the rank specified.
Thanks for your help in advance!