You need to sign in to do that
Don't have an account?
Simon 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>
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>
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>
<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