I am using the
following code to do a few things. List locations, get me a running total of the
instances that have been created within that location, and the percentage of the
instances for that location. The first two work fine. What is happening is
when I output the percentage I am getting incrementing values. For instance, I
have this:
| Area | Count | Percent |
|---|---|---|
| PACU Roberts | 63 | 8.35% |
| PACU Truett | 59 | 8.92% |
| 9R | 44 | 11.95% |
| 14R | 34 | 15.47% |
| 3RN CCU | 24 | 21.92% |
| 5J | 24 | 21.92% |
| 7J | 24 | 21.92% |
| 10R | 22 | 23.91% |
| 15R | 20 | 26.30% |
| 4J | 18 | 29.22% |
| 7R | 18 | 29.22% |
| OR Roberts | 18 | 29.22% |
| 2TW | 17 | 30.94% |
What is
happening is the percentage is incrementing. I am not sure what I am dong wrong.
Also, I am sure that the problem is staring me in the face, but
(insert forrest/tree quote here) The code follows:
<!---
Create the array to store all of the totals of the LocationCount
--->
<cfset locationCountArray = ArrayNew(1)>
<cfset locationCountArray = ArrayNew(1)>
<!--- Count all of the locations in the
FormInstances table. --->
<cfquery datasource="#Application.DataSource#" name="qGetLocationCount">
SELECT Count(FormInstances.PatientLocation) AS LocationCount, FormInstances.PatientLocation AS Location
FROM FormInstances
WHERE FormInstances.PatientFacility='#Form.PatientFacility#'
GROUP BY FormInstances.PatientLocation
ORDER BY LocationCount DESC
</cfquery>
<cfquery datasource="#Application.DataSource#" name="qGetLocationCount">
SELECT Count(FormInstances.PatientLocation) AS LocationCount, FormInstances.PatientLocation AS Location
FROM FormInstances
WHERE FormInstances.PatientFacility='#Form.PatientFacility#'
GROUP BY FormInstances.PatientLocation
ORDER BY LocationCount DESC
</cfquery>
<!--- We need to set a temp variable
--->
<cfset temp = 1>
<cfset temp = 1>
<!--- We need to output the query results from
qGetLocatonCount query --->
<cfoutput query="qGetLocationCount">
<cfset locationCountArray[temp] = LocationCount>
<cfset temp = temp + 1>
</cfoutput>
<cfoutput query="qGetLocationCount">
<cfset locationCountArray[temp] = LocationCount>
<cfset temp = temp + 1>
</cfoutput>
<cfoutput>
<cfset TotalCount = #ArraySum(locationCountArray)#>
</cfoutput>
<cfset TotalCount = #ArraySum(locationCountArray)#>
</cfoutput>
<table width="500" border="0" cellpadding="2"
cellspacing="2">
<tr>
<th align="left">Area</th>
<th align="left">Count</th>
<th align="left">Percent</th>
</tr>
<cfloop query="qGetLocationCount">
<cfoutput>
<cfset Percentage = #TotalCount# / #LocationCount#>
<tr>
<td align="left">#Location#</td>
<td align="left">#Locationcount#</td>
<td align="left">#DecimalFormat(Percentage)#%</td>
</tr>
</cfoutput>
</cfloop>
</table>
<tr>
<th align="left">Area</th>
<th align="left">Count</th>
<th align="left">Percent</th>
</tr>
<cfloop query="qGetLocationCount">
<cfoutput>
<cfset Percentage = #TotalCount# / #LocationCount#>
<tr>
<td align="left">#Location#</td>
<td align="left">#Locationcount#</td>
<td align="left">#DecimalFormat(Percentage)#%</td>
</tr>
</cfoutput>
</cfloop>
</table>
Bruce Sorge
Portal Services
Baylor Health Care
Systems
Phone: 214-820-3142
Sorge, Bruce.vcf