Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 19th, 2011, 10:49 AM
rpowell460 rpowell460 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 rpowell460 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 49 sec
Reputation Power: 0
Using IIF and Sum Expressions in SSRS

In SSRS I am trying to SUM up a field, based on the value of another field.

Example:
If field Title Code is A or B or C, sum up the Title Code Count.
TitleCode TeacherCount
T046 32
T064 1
T072 1
Total 34

I would like to do this using an expression in a report. Here is the expression I created using IIF and SUM. But it throws an error?

=Sum(IIF(Fields!TitleCode.Value = "T046" OR "T064" OR "T072","", Fields!TeacherCount.Value))

Reply With Quote
  #2  
Old December 26th, 2011, 03:14 AM
eralpery eralpery is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 19 eralpery User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 37 m 49 sec
Reputation Power: 0
Using OR is causing the error.
Perhaps it is better to use the following :

Code:
=Sum(IIF(Fields!TitleCode.Value = "T072",0, (IIF(Fields!TitleCode.Value = "T064",0, (IIF(Fields!TitleCode.Value = "T046",0, Fields!TeacherCount.Value))))))

Reply With Quote
  #3  
Old December 26th, 2011, 03:39 AM
eralpery eralpery is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 19 eralpery User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 37 m 49 sec
Reputation Power: 0
An other method, perhaps a better one is using custom code in Reporting Services report and building your own function

Here is the source code for the function. (Please note it might require some corrections)

Code:
Public Shared Function GetCount(txt as String, tcount as integer) As integer

	if(txt = "T046" OR txt = "T064" OR txt = "T072") then 
		return 0
	else
		return tcount
		
End Function



And here is how you will use it in your table field.
Code:
=Sum(Code.GetCount(Fields!TitleCode.Value, Fields!TeacherCount.Value))


I hope that helps,

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Using IIF and Sum Expressions in SSRS


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap