SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


COUNT


COUNT

Author
Message
sharonsql2013
sharonsql2013
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1304 Visits: 1265
I am trying to get a sum of of all devices where the count is > 1
Count(IIF(Count(Fields!Device_Name.Value)>1 , Count(Fields!Device_Name.Value),0)

But the above expression gives me 1 even though there are no devices with count> 1

SUm(IIF(Count(Fields!Device_Name.Value)>1 , Count(Fields!Device_Name.Value),0) gives error.

Any ideas?
higgim
higgim
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1504 Visits: 2631
Can you provide some sample data and I will have a look at this for you. Until then, I will make an assumption:

You could re-write / write a query which will work it out for you in advance.

-- Assuming your test data looks something like this???
DECLARE @TestData TABLE
(
Devicename NVARCHAR(100)
)
INSERT INTO @TestData
( Devicename
)
SELECT 'IPhone'
UNION ALL
SELECT 'IPhone'
UNION ALL
SELECT 'HTC'
UNION ALL
SELECT 'Nokia'
UNION ALL
SELECT 'HTC';
WITH MoreThanone
AS ( SELECT Devicename ,
COUNT(Devicename) AS DeviceCount
FROM @TestData
GROUP BY Devicename
HAVING COUNT(Devicename) > 1
)
SELECT SUM(DeviceCount) AS TotalCountofDevicesWhereCountMoreThanOne
FROM MoreThanone



The above can then be used anywhere on your report.


Failing that, (The only way I can see) break down the problem by putting the returned data into a Tablix on the report and create an expression to return the count if it's greater than 1 otherwise return 0. The unfortunate part is that you cannot then use those values in an aggregation other that the header or footer of a report. In this case I have used the header and all looks good. (See image attached)
Attachments
Count.jpg (9 views, 15.00 KB)
j-1064772
j-1064772
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1289 Visits: 1213
I have encountered a similar situation w/r to placing sums only in footers.

What I did instead was to generate in T-SQL a table variable which is first populated by the raw data then another T-SQL statement inserts summed up records. I have added an extra column which flags each record as Raw or Sum and use the SSRS's Conditional Row Visibility to print a subtotal record in a group of the raw records (also filtered as per the Raw flag).
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search