September 2010
S M T W T F S
« Jun    
 1234
567891011
12131415161718
19202122232425
2627282930  

Avoiding a Nested Mess

Have you ever tried to do a nested IF THEN ELSE statement inside IBM Cognos Report Studio? If you have, you might run screaming because you can’t get the syntax just right. Granted, you could read the tips at the bottom as you build the syntax but shoot yourself in the head if you are not a programmer. You probably could pickup Chinese faster.

Here is an example:
I want the total of A if A is greater than B, however if C is greater than D then I want the Average of C. If neither condition is met then I want the count of A.

In this example I am using total, count, and average all as expressions and each requires its own syntax. First build each expression:

Total (A)
Average(C)
Count (A)

Before you run off to build your nested calculations, you must remember that ELSE must go before each  IF after the first IF. Now that you have the proper syntax for the expression part of the IF THEN ELSE you are ready to build your nested statement.

The build is as follows:
IF (A > B) THEN (Total(A))
ELSE IF(C>D) THEN (Average (C))
ELSE (Count(A))

Remember that every IF must have an ELSE match in order for the syntax to be correct. I always think of the ELSE as an period at the end of a sentence. When I have more to say I end my first statement and start talking (insert an IF) and end that statement with a period (ELSE).

You must be logged in to post a comment.