Solved

SSRS Conditional Formatting - Muliple conditions

Posted on 2012-03-17
3
734 Views
Last Modified: 2012-03-19
I am setting up a conditional format for background colours in a report.  See attachment for example of the report content.

I have created this expression under text box properties/fill...

=iif((Fields!time.Value < cdate(Today & " 08:00:00")), "Green", (iif(Fields!time.Value > cdate(Today & " 08:10:00"), "red", "white")))

So, if time is before 8am colour is green, beween 8:00  and 8:10 colour is white, after 8:10 is red.  

What I have above works however I only want to apply it to rows where the Load field is "first".  For rows where Load is "Last" I want to use a similar conditional format to the above, but with time values for later on in the day.

Theoretically I want to have something like..

if load = "first" then do
=iif((Fields!time.Value < cdate(Today & " 08:00:00")), "Green", (iif(Fields!time.Value > cdate(Today & " 08:10:00"), "red", "white")))

else

if load = "last" then do
=iif((Fields!time.Value < cdate(Today & " 15:00:00")), "Green", (iif(Fields!time.Value > cdate(Today & " 15:10:00"), "red", "white")))

Is this possible in SSRS?
Capture.JPG
0
Comment
Question by:joemccnz
3 Comments
 
LVL 15

Expert Comment

by:TimHumphries
Comment Utility
Hi,

Should be something like:

=IIF(Fields!Load.Value = "first",
iif((Fields!time.Value < cdate(Today & " 08:00:00")), "Green", (iif(Fields!time.Value > cdate(Today & " 08:10:00"), "red", "white")))
,
iif((Fields!time.Value < cdate(Today & " 15:00:00")), "Green", (iif(Fields!time.Value > cdate(Today & " 15:10:00"), "red", "white")))
)

i.s. just nesting your existing formulae.

Tim
0
 
LVL 37

Accepted Solution

by:
ValentinoV earned 500 total points
Comment Utility
Another option, and easier to read/maintain, is using the Switch instead of the IIF:

=Switch(
  (Fields!Load.Value = "first") AND (Fields!time.Value < cdate(Today & " 08:00:00")), "Green",
  (Fields!Load.Value = "first") AND (Fields!time.Value > cdate(Today & " 08:10:00")), "red",
  (Fields!Load.Value = "last") AND (Fields!time.Value < cdate(Today & " 15:00:00")), "Green",
  (Fields!Load.Value = "last") AND (Fields!time.Value > cdate(Today & " 15:10:00")), "red",
  True, "white"
)

More info on the Switch: http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/A_2279-Adding-an-Else-to-your-Switch.html
0
 

Author Comment

by:joemccnz
Comment Utility
Thanks  ValentinoV, good article.  Switch looks like the way to go..  however using the code you posted above everything is coloured white?

edit.. Just realized I needed to change the "First" and "Last" fields to start with capital letters, its working fine now, thanks
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now