Cognos Report Studio Nested IF Statements
Have you ever tried to do Cognos Report Studio nested IF statements and created a mess? 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 of a Cognos Report Studio nested IF statement I want to create:
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)
• 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 in Cognos Report Studio. 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 Cognos Report Studio nested IF statement is as follows:
IF (A > B) THEN (Total(A))
ELSE IF(C>D) THEN (Average (C))
Remember that every IF must have an ELSE match in order for the syntax to be correct in Cognos Report Studio. 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).
I hope this has helped you become an expert at Cognos Report Studio nested IF statements. If you liked this tip or want to share others, please add a comment. For more tips join the Lodestar Solutions community on our website at www.lodestarsolutions.com. If you need additional consulting or training on IBM Cognos BI please contact us at firstname.lastname@example.org.