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
Simon BairdSimon Baird 

Calculating two aggregate values using Apex

Hi all,
I am trying to divide to numbers produced from aggregate result in an apex class. Am able to retrive the values (tx and wd) and present them on the VF page widget but would like to divide one by the other and present the result.i.e. tx/wd

public AggregateResult[] AvTx{
        get {
            return [SELECT SUM(Working_Days__c)wd,SUM(Total_Treatments__c)tx FROM Session__c WHERE Session_Completed__c = true AND OwnerID = :u AND Date__c >= :dtps AND (Session_Coverage_Type__c = 'Regular' OR Session_Coverage_Type__c = 'Regular Rescheduled') AND Session_Type__c != 'Emergency' AND Exclude_Session_From_Pod_Tier_Average__c = false];
            }

<apex:page controller="OpenSessionsList" readOnly="true">
   <apex:pageBlock >
        <apex:pageBlockTable value="{!AvTx}" var="r">
            <apex:column >
            <apex:facet name="header">Average Treatments</apex:facet>
             {!r['wd']}
             </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>    
</apex:page>
Raj VakatiRaj Vakati
Hi ,
Can you try like this . 
 <apex:column >
            <apex:facet name="header">Average Treatments</apex:facet>
         <apex:outputfield
  >

   {!r['wd']} + {!r['tx']}
         </apex:outputfield  >
 
            </apex:column>
 
Simon BairdSimon Baird
Thanks Rajamohan I think it's almost there. I used OutputText instead of Outputfield

<apex:page controller="OpenSessionsList" readOnly="true">
   <apex:pageBlock >
        <apex:pageBlockTable value="{!AvTx}" var="r">
            <apex:column >
            <apex:outputText value="{!r['tx']}/{!r['wd']}"></apex:outputText> 
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>    
</apex:page>

It now displays the arithmetic not the answer i.e. "13/2" not 7.5