Solved

SSRS Conditional Formatting - Muliple conditions

Posted on 2012-03-17
3
745 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:Tim Humphries
ID: 37734667
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
ID: 37736463
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
ID: 37739284
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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…
Viewers will learn how the fundamental information of how to create a table.

920 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