I want to display Grand Total Amount and Total Amount(Particular Column total) but its not working.

Please help me to achieve this. 1)Here Grand total is total of Amount__c in Expensive__c object and 2)Total Amount is Particular Column total displayed in pageblocktable, in below image you can see its only showing Total amount is 56.

enter image description here

VF Page:

<apex:page controller="ExpensesClass" >

<apex:form >
<!-- Need this variables for totals generation -->
<apex:variable value="{!0}" var="total1"/>

<apex:pageBlock >

<apex:pageBlockTable value="{!expensesList}" var="e" rendered="{!isTableExit}" >

<apex:column value="{!e.Date__c}"/>
<!--<apex:column value="{!e.Item__c}"/>-->
<apex:column >
<apex:outputLink target="_blank" value="/{!e.id}">{!e.Item__c}</apex:outputLink>

<apex:column headerValue="Amount">
<apex:outputField value="{!e.Amount__c}" />
<apex:variable var="total1" value="{!e.Amount__c}" />
<apex:facet name="footer">
               Total: <span class="t1"></span>   

<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Grand Total Amount:"/>
<apex:outputText value="{!totalsum1}"/>
// Here we will set the generated subtotals to the footer cells

document.getElementsByClassName('t1')[0].innerHTML = '{!total1}'; 


public class ExpensesClass {
public string nameQuery{get;set;}
public List<Expense__c> expensesList{get;set;}
public Boolean isTableExit {get;set;}
public Date fromdate {get; set;}
public Date todate {get; set;}
public list<AggregateResult> totalsum {get;set;}
public integer totalsum1{get;set;}

//public List<Expense__c> expensesList {get; set;}
public ExpensesClass(){
totalsize=[Select count() From Expense__c];
totalsum=new list<AggregateResult>();
//totalsum=[Select sum(Amount__c) From Expense__c];

public PageReference executeSearch(){
string str='%'+nameQuery+'%';
if(nameQuery==null || nameQuery==''){
    //errormessage ='Name cannot be null or empty. Please Try Again.';
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter Owner Name'));
expensesList=[Select id, Item__c, owner.name,Amount__c, Date__c From Expense__c where owner.name LIKE:str Limit:limitsize Offset:offsetsize];

return null;

public Void gettotalsum1(){
AggregateResult[] groupedresult=[Select sum(Amount__c) From Expense__c];
object totalsum1=groupedresult[0].get('total');
//return totalsum;

Thanks in advance Shaik

1 Answer 1


Completely in the context in what you posted / are asking, you are not adding the values which is why it only shows the last value....

You need to:

<apex:variable var="total1" value="{!e.Amount__c + total1}" />
  • Hi, Thanks for your response, now column total working fine. how to display grand total.
    – Shaik
    Aug 25, 2015 at 16:24
  • 2
    @Shaik - Please mark as accepted answer then so others looking for similar questions can find ones with an answer
    – Eric
    Aug 25, 2015 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .