COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: PeterDD on 20 Aug 2019 06:00:41 AM

Title: How to add an calculated field in a query that works like an ID or Autonumber
Post by: PeterDD on 20 Aug 2019 06:00:41 AM
Hello, I've created a datamodule from a package in Cognos 11.

The data collected from a table does not have an ID field so I want to create the ID field manually.

is it possible to make a calculated field that generates an unique number for each row in the query?
:-\
Title: Re: How to add an calculated field in a query that works like an ID or Autonumber
Post by: oscarca on 20 Aug 2019 06:27:51 AM
You could create a row counter data item e.g. running-total([Data Item]) which gives you a number för each row.
You can also create a layout calculation using the RowNumber() function.
Title: Re: How to add an calculated field in a query that works like an ID or Autonumber
Post by: PeterDD on 20 Aug 2019 07:05:41 AM
Nice ;D

thanks!
Title: Re: How to add an calculated field in a query that works like an ID or Autonumber
Post by: oscarca on 20 Aug 2019 07:16:23 AM
Or you could create a data item that creates a specific number depending on the value/string of a certain column:
case
when [Data item] = 'Car' then 1
when [Data item] = 'Train' then 2
when [Data item] = 'Boat' then 3
else null
end

No problem  :)
Title: Re: How to add an calculated field in a query that works like an ID or Autonumber
Post by: bus_pass_man on 20 Aug 2019 08:21:11 AM
Is it possible that the keys in your query subject were hidden in the package?  If you need to use them, change the package to expose them.   

It is possible that the techniques above could produce results which could vary over time.