Cognos Analytics

 View Only

Ambiguous Identifiers in Cognos Reports

By Marc Reed posted Tue January 09, 2024 09:13 AM

  

Reading a blog post about Cognos 12's new translation functionality and identifiers reminded me that sometimes you can write ambiguous report expressions within Cognos. As report authors we should always make sure there is no ambiguity in our code - we want to make it obvious what our reports are doing. Anyone maintaining our development should know what we intended - and that we didn't get the answer we wanted by accident!

This idea of removing ambiguity can be shown with how its possible to create ambiguous expressions within a Cognos report's data expressions. 

Data Module Standalone Objects Identifiers

Consider the sample Great outdoors data module.

I have created a standalone calculation named Prod which also has an identifier of Prod. It simply references the Product within the Products query. Within the Data Module this calculation looks like:

And shows a list of product names.

If I use this data module standalone calculation in a report query data item then the expression looks like:

In a standalone calculation there is no query qualifier.

From previous posts you may remember that we can remove the data module qualifier from any data items.

  1. It allows us to easily move a report from one data module to another.
  2. The Filter Text shown to report consumers in interactive reports is far better.
When removing the Data Module Qualifier this item becomes:
The query for this report looks like:
I am going to change the report query Prod data item to this:

Simply prefixing the product name with two asterix. Running the report you see what you would expect:

Now the fun part…
I am adding another new calculation to my report. From the Data Items tab, I add the Prod data item.

Look at that expression: [Prod]. Isn’t this the exact same way that we referred to the Data Module Prod data item right at the beginning? A reminder that expression looked like:

We have ambiguity.

In the New Calculation data item, does [Prod] refer to the Data Item [Prod] in the same query, or to the [Prod] in the data module? What are your thoughts?
Ambiguity is never nice to have. If you remember back to maths then there are clear rules around ambiguity and we end up with things like BODMAS. But there are no rules written for this situation.

Well, we can try the report and see.

The report shows that [Prod] refers to the data module [Prod] and not the query [Prod].

As report authors we should remove this ambiguity to ensure that anyone maintaining our report knows that we get this result on purpose and not by chance.

In this case a we should rename the report query [Prod] data item – as the report author this is the only thing under our control.

0 comments
5 views

Permalink