# Running Balance & Row Auto-Number

• Question
• Updated 5 years ago
I have a custom object that tracks Tuition Payments. Sometimes, a student could be behind on several payments and thus the "Amount Due" would not match the "Amount Received" for that month. How would I go about creating a dynamic "Running Balance" field like the screenshot below?

I'm thinking the only way this would work is if I were able to dynamically auto-number and index the rows in the Payment Table. And then assign the "Running Balance" field to be a formula that calculates a new Balance (based on the Balance of the rows that proceeded it).

However, I've hit a brick wall and am not sure how I'd actually implement this, or if my train of thought is correct.
Any guidance would be greatly appreciated.
• 2,802 Points

Posted 5 years ago

Moshe Karmel, Champion

• 8,686 Points
This can be done with a pretty simple field renderer check out some of the documentation on that but the idea is something like this:
1) Drag a random number field into the table
2) Set the field renderer as custom
3) create a javascript snippet like so...

`var field = arguments[0],    value = arguments[1],   \$ = skuid.\$;var row = field.row;var amountDue = row.Amount_Due__c;var amountReceived = row.Amount_Received__c;value = (amountDue - amountReceived);skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);`

Zach McElrath, Employee

• 52,370 Points
You can create a Row Auto-Number by adding a Template Field into the Table, and using {{index}} as the Template Body.

The Running Balance will need to be done with a Custom Field Renderer, which requires JavaScript, where you could look at the current row, get its position within the Model's data, and using this information, go find the previous row and grab field values off of it and calculates the running balance as of that point. See the tutorial on Custom Field Renderer snippets.