Home
Analytics
Aggregation Count different from SQL Count
Auroras
Hi all, I have a table named wintelCosts, and the columns of interest for me in this table are activityStatus and serverPurpose.<br />
<br />
Fields in the column serverPurpose range from 'Application' to 'Infrastructure' to 'Web', among others, and activityStatus are either 'Active', 'Not Active', or 'Decommissioned'. <br />
<br />
I want to find out, say, how many active Wintel servers are there having serverPurpose = 'Application', so I try it out first using the Data Set SQL Query:<br />
<br />
<span style='font-family: Courier New'>select count(*) as ApplicationCount<br />
from wintelCosts<br />
where activityStatus = 'Active' and serverPurpose = 'Application'</span><br />
<br />
Which has an output of 191, which is what I want.<br />
<br />
However, I have to come up with a count output for all of these combinations ('Application' and active, 'Infrastructure' and active, etc.), so I start looking for a computed column solution. I create a computed column called ApplicationCount, and edit my SQL Query to be this:<br />
<br />
<br />
<span style='font-family: Courier New'>select * from wintelCosts</span><br />
<br />
The computed column has an integer DataType, a COUNT aggregation, and both the expression and filter (I still don't know the difference between the two) are set to <br />
<br />
<span style='font-family: Courier New'>row["serverPurpose"] == 'Application' && row["activityStatus"] == 'Active'</span><br />
<br />
And I get a count of 189, 2 fewer than the correct count. I have no idea why this is happening, could anyone help me out here? Thank you!
Find more posts tagged with
Comments
Auroras
I am able to reproduce this with this trimmed down sample Excel spreadsheet. I link the table in Access (without importing it) and I link it to BIRT using <a class='bbc_url' href='
http://digiassn.blogspot.com/2008/02/birt-birt-reporting-for-microsoft.html'>this
guide.</a>
Tubal
Without seeing your actual data, it's hard to say why the counts would be different.
1. Is this in Preview only? Maybe you have your preview row limit set to lower than the actual returned results.
2. Could be that there are some spaces somewhere that BIRT sees that SQL doesn't.
3. Maybe you have an additional filter on the BIRT table that you forgot about.
I would probably remove the filter in the expression and use it only in the filter section of the aggregate, or the table.
So your expression would read something like row["billDate"] (it doesn't really matter which row you count, as long as the value is never null) and then you would put the filters in your filter. Theoretically it shouldn't matter. But maybe it's throwing it off.
Auroras
I'm continuing to play with the query, and now I've found out that without changing the properties for the computed column, I can get it to output the correct results by changing the <em class='bbc'>SQL Query</em> from<br />
<br />
<span style='font-family: Courier New'>select * from wintelCosts</span><br />
<br />
to<br />
<br />
<span style='font-family: Courier New'>select * <br />
from wintelCosts<br />
where activityStatus = 'Active' and serverPurpose = 'Application'</span><br />
<br />
So basically I can count correctly if the SQL Query was already restricted to output only those that I want to count. If the SQL Query outputs a lot of other things and I try to count it in the expression builder, something screws up.<br />
<br />
From the preview results I see that there are 2 rows where the billDate is different from the rest of the rows: the billDates for almost all the others are in May, whereas the billDates for the last two are for different dates. I don't know if this somehow plays into the discrepancy or just a coincidence.<br />
<br />
Otherwise my progress has been slow.
Auroras
Turns out your first response was what was wrong:<br />
<br />
<blockquote class='ipsBlockquote' data-author="'Tubal'" data-cid="105167" data-time="1340643497" data-date="25 June 2012 - 09:58 AM"><p>
Without seeing your actual data, it's hard to say why the counts would be different.<br />
<br />
1. Is this in Preview only? Maybe you have your preview row limit set to lower than the actual returned results.<br />
<br /></p></blockquote>
<br />
When I looked at the data set editor, only the first 500 results were shown, and that for some reason the count column stopped at row 500 and didn't go any further. I tweaked the Data Set Editor display row settings (Window - Preferences - Report Design - Data Set Editor) to show the maximum number of allowed rows, and now everything's behaving as it should be!<br />
<br />
Thank you.