COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: Manu0521 on 16 Apr 2014 01:18:49 PM

Title: changing the label of data name based on other column
Post by: Manu0521 on 16 Apr 2014 01:18:49 PM
I will be using three data items which will be calculated from current year, say the column names can be
2013
2014
2015

or it could be 2012
                      2013
                      2014

Now my new 2 columns will find the change in value for the above three columns.

say it could be 2012-2013 or 2013-2014

since I have 3 data items I can subtract the first 2 and last 2 but how do dynamically name them

Thanks,
Title: Re: changing the label of data name based on other column
Post by: navissar on 17 Apr 2014 03:05:13 AM
You could try to use a report expression for your column header, instead of member caption/data item label. Then write an expression which will take the dynamic values of the relevant data items...
Title: Re: changing the label of data name based on other column
Post by: navissar on 17 Apr 2014 10:00:05 AM
For future people's reference (Hello people from the future! Have you worked out global warming yet, or are you all wearing shorts?)
Manu had written me that he had tried these expressions:
extract(year,current_date) or extract(year,today())
and got a parsing error.

I had answered that when extract is used in the context of a report expression, it is an extremely unforgiving function.
First, the date it is fed HAS TO BE either a timestamp or a date-time type. current_date isn't a report expression, and today() returns a date, not date-time. So, the date part should look like this: date2timestamp (today())
This will convert today's date to a timestamp with 00:00:00.000 as the time.
Next, it doesn't say so in the documentation (Kudos, IBM), but the date part should be in single quotes. So, to get today's year in a report expression we need to use the following syntax:
extract('year',date2timestamp (today()))
and if we want to make the thousand separator disappear, we need to cast the whole thing to text, so the expression is:
number2string(extract('year',date2timestamp (today())))
Title: Re: changing the label of data name based on other column
Post by: Manu0521 on 17 Apr 2014 11:41:20 AM
Thanks Nirmod. It worked perfectly.