Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SSRS Conditional Formatting - Muliple conditions

Posted on 2012-03-17
3
Medium Priority
?
776 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

670 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