function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John NeffJohn Neff 

Using AggregateResult & GROUP BY ROLLUP- "Total" row returned at top instead of bottom

Good Evening, 

I am using AggregateResult and GROUP BY ROLLUP to output some data.  After a long slog, I've got it working the way I need it to... except for one thing.  The "Total" row is showing at the top of the list instead of the bottom when I put the data into a table. 

Would anybody be able to help me get my total row so that it is the last item in the table?

Here is my VF page: 
<apex:page controller="CurrentWeekDY">
 
 <apex:pageBlock title="Delivery WTD">
 <apex:pageBlockTable value="{!DelSumOut}" var="dy">
   <apex:column value="{!dy.Campaign}" headerValue="Campaign" />
   <apex:column value="{!dy.Delivery}" headerValue="Delivery" />  
 
 </apex:pageBlockTable>
 </apex:pageBlock>
 
 

And here is my controller: 
public class CurrentWeekDY {
    public class DelSum {
        public String Campaign {get; set;}
        public String Delivery {get; set;}

        public DelSum(string c, string d) {
            this.Campaign = c;
            this.Delivery = d;
        }
    }

    public List<DelSum> DelSumList = new List<DelSum>();

    public List<DelSum> getDelSumOut() {
        AggregateResult[] AgR = [SELECT Camp__c, SUM(Spend__c) FROM TL_Client__c WHERE CWDelivery__c = TRUE GROUP BY ROLLUP(Camp__c) ORDER BY Camp__c];

        for (AggregateResult DYList : AgR) {
            DelSumList.add(new DelSum(String.valueOf(DYList.get('Camp__c')), String.valueOf(DYList.get('expr0'))));
        }

        return DelSumList;
    }
}


I would really appreciate any help!!

Thanks, 
 

John 

Gururaj BGururaj B
on your page you are just displaying a list object. Not sure how Total field is even appearing on top  of  your table. I dont see any tag to show total.
Ricky_ThedaRicky_Theda
<apex:page controller="CurrentWeekDY">
 
 <apex:pageBlock title="Delivery WTD">
 <apex:pageBlockTable value="{!DelSumOut}" var="dy">
   <apex:column value="{!dy.Campaign}" headerValue="Campaign" />
   <apex:column value="{!dy.Delivery}" headerValue="Delivery" />  
   <apex:variable var="total1" value="{!dy.Delivery + total1}" />
 </apex:pageBlockTable>
  {!total1}
 </apex:pageBlock>
John NeffJohn Neff
thanks Rick, unfortunately I'm still stuck with the total at the top 
Ricky_ThedaRicky_Theda
It is because your method getDelSumOut(), and you are use it as variable on pageBlockTable. Try to declare delSumList on constructor and change pageBlockTable variable to delSumList instead of delSumOut. Let me know if the total still on the top.
John NeffJohn Neff
Thatnks for your help Rick, I changed the constructor to delSumList and am still getting the total on the top!  Do I need to flip the order of my strings?  
 
public class CurrentWeekDY {
    public class DelSum {
        public String Campaign {get; set;}
        public String Delivery {get; set;}

        public DelSum(string c, string d) {
            this.Campaign = c;
            this.Delivery = d;
        }
    }

    public List<DelSum> DelSumList = new List<DelSum>();

    public List<DelSum> getDelSumList() {
        AggregateResult[] AgR = [SELECT Camp__c, SUM(Spend__c) FROM TL_Client__c WHERE CWDelivery__c = TRUE AND Spend__c > 0 GROUP BY ROLLUP(Camp__c) ORDER BY Camp__c];

        for (AggregateResult DYList : AgR) {
            DelSumList.add(new DelSum(String.valueOf(DYList.get('Camp__c')), String.valueOf(DYList.get('expr0'))));
        }

        return DelSumList;
    }
}
<apex:pageBlock title="Delivery WTD">
 <apex:pageBlockTable value="{!DelSumList}" var="dy">
   <apex:column value="{!dy.Campaign}" headerValue="Campaign" />
   <apex:column value="{!dy.Delivery}" headerValue="Delivery" />  

 </apex:pageBlockTable>
 
 </apex:pageBlock>