VBAmazing
VBAmazing

Reputation: 52

Cognos Report Studio: How can I change the image displayed based on a query output?

Using Cognos Report Studio:

I have a query that returns two numbers, and based on those two numbers I need to display an up, down or straight arrow. Images stored in the server.

Here are my conditions:

If (num1 > num2) then (green arrow)
If (num1 < num2) then (red arrow)
If (num1 = num2) then (straight arrow)

I've tried using a string variable called vImage with the following condition:

case
   when (num1 > num2) then (GreenArrow.png)
   when (num1 < num2) then (RedArrow.png)
   when (num1 > num2) then (StraightArrow.png)
end

With num1 and num2 as query results. Those .png files are my list of answers.

On my report, I have the Image layout element with the URL Source Variable set to that Image variable.

When I Run HTML though, the report element returns blank.

I have tried selecting and un-selecting values in the URL source variable dialog, but nothing seems to be working.

Any advice?

Upvotes: 0

Views: 686

Answers (2)

dougp
dougp

Reputation: 3087

You don't need to define a variable.

For your image column:
Set the URL Source | Source Type property to Report expression.
Set the expression to something like this:

'/Graphics/' + 
case
    when [Query1].[num1] > [Query1].[num2]
        then 'Green'
    when [Query1].[num1] < [Query1].[num2]
        then 'Red'
    else 'Straight'
end
 + 'Arrow.png'

Adjust to accommodate the actual path to your images.
You'll also need to consider the effects of how you craft your URL on the output format. HTML image URLs are evaluated by the client browser. Image URLs in Excel or PDF output are evaluated by the Cognos service. Images may appear in one output format and not another.

Upvotes: 1

Daniel Wagemann
Daniel Wagemann

Reputation: 851

Given the requirement is just up and down arrow I really would not bother with images at all. Simply copy the ascii arrow into the if clause. https://unicode-table.com/en/sets/arrow-symbols/#up-arrows. Once completed, use the conditional style to adjust the font color.

case
   when (num1 > num2) then (▲)
   when (num1 < num2) then (▲)
   when (num1 > num2) then (▲)
end

Upvotes: 2

Related Questions