I have created a simple table of data in a VF page, which uses Apex:Repeat to list records.

There is a column that contains a cumulative amount, by way of apex:variable. The cumulative amount works fine and repeats, however i need to add a starting amount (currentRecord.Opening_Balance__c) at the top of the column, which the first record in the list uses as a opening amount.

The issue is, adding the variable to the first record amount, and not to every record amount thereafter.


The table on the left is what i am trying to achieve. The table on the right is what I have currently, without applying the "Opening Balance" variable.

I haven't seen this applied elsewhere, so any thoughts would be appreciated...


<apex:outputPanel id="records" styleClass="panel">
    <table style="width:100%;">
                <th style="text-align:left">Date</th>
                <th style="text-align:left">Transaction Details</th>
                <th style="text-align:left">Withdrawals</th>
                <th style="text-align:left">Deposits</th>
                <th style="text-align:left">Balance</th>
        <apex:variable value="{!0}" var="Total"/>
        <apex:variable value="{!currentRecord.Opening_Balance__c}" var="open"/>
                <td colspan="4"><b>Opening Balance</b></td>
            <apex:repeat value="{!remittanceAdvice}" var="re" >
                <td><apex:outputfield value="{!re.Date__c}"/></td>
                    <apex:variable var="Total" value="{!Total - re.Remittance_Total_Debit__c + re.Remittance_Total_Credit__c }"/>
                <td colspan="4"><b>Closing Balance</b></td>
  • You have already added this <apex:variable value="{!currentRecord.Opening_Balance__c}" var="open"/> what else you want to add here? – Tushar Sharma Oct 5 '18 at 11:35
  • Tushar, the variable is there, however i cant use it. If i apply to the total in the repeat list, it will iterate over every record. – TheMikeyBoosh Oct 5 '18 at 11:37
  • You can add that before the repeat. – Tushar Sharma Oct 5 '18 at 11:39
  • Thats correct, but the first record amount of the repeat will ignore it in the cumulative total – TheMikeyBoosh Oct 5 '18 at 11:40
  • 1
    Will this not work for you <apex:variable value="{!currentRecord.Opening_Balance__c}" var="Total"/> – Tushar Sharma Oct 5 '18 at 12:11

Kudos to Tushar (see comments).

Changing the variable (var) worked.

<apex:variable value="{!currentRecord.Opening_Balance__c}" var="open"/>


<apex:variable value="{!currentRecord.Opening_Balance__c}" var="total"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.