COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: mprof on 01 Jan 2014 05:16:55 AM

Title: crosstab custom calculation
Post by: mprof on 01 Jan 2014 05:16:55 AM
Hi,

i have a crosstab of fruits/vegetables :

                                                         
                  oranges                              apples                     tomatoes                               
Day1          100                                       30                          50                       
Day2          150                                       40                          60                               
..
Total           1000                                    350                         400             

I have a Total to summarize the  data until yesterday.
I want to add a row that calculates the average multiply the number of days left in the month.

please advise on how can i do so.

thanks
Title: Re: crosstab custom calculation
Post by: BigChris on 02 Jan 2014 05:44:50 AM
The days left in the month can be calculated along the lines of:

_days_between(getdate(),_last_of_month(getdate()) - obviously it depends on your platform etc. You should then be able to multiply that by your average
Title: Re: crosstab custom calculation
Post by: mprof on 02 Jan 2014 05:53:55 AM
thanks but the problem is not with the calculation itself.
i have a problem to add it to the crosstab.
I can only add the given functions (like total, average etc.) and not custom.
Title: Re: crosstab custom calculation
Post by: MFGF on 02 Jan 2014 06:19:49 AM
Hi,

Go to the toolbox and drag in a query calculation below the existing rows in the crosstab. You can code the expression as whatever you need it to be.

Cheers!

MF.
Title: Re: crosstab custom calculation
Post by: mprof on 02 Jan 2014 06:27:42 AM
I have tried this, but all i get is an empty line
Title: Re: crosstab custom calculation
Post by: MFGF on 02 Jan 2014 06:29:40 AM
What expression did you use?

MF.
Title: Re: crosstab custom calculation
Post by: mprof on 02 Jan 2014 06:41:33 AM
query calculation:
total([sql1].[orange])/3
Title: Re: crosstab custom calculation
Post by: MFGF on 02 Jan 2014 06:58:50 AM
What is [Orange] - is it the default measure of the crosstab?
Title: Re: crosstab custom calculation
Post by: mprof on 02 Jan 2014 07:31:11 AM
it's a query result.
aggregation of 'orange' by day
Title: Re: crosstab custom calculation
Post by: MFGF on 02 Jan 2014 07:52:48 AM
Is there a default measure, or are "Oranges", "Apples" and "Tomatoes" all separate items?

If you have a default measure, what happens if you try an expression like total([your default measure] for [day item in your rows]) / 3

The other thing that occurred to me is that previously you indicated you have an item [sql1].[orange] - I'm hoping this doesn't indicate you have hard-coded SQL in the query? Can you clarify?

MF.
Title: Re: crosstab custom calculation
Post by: mprof on 02 Jan 2014 08:00:45 AM
I do have sql query.
it's something i inherited and cannot change it now :/
and yes each item is sperated
Title: Re: crosstab custom calculation
Post by: MFGF on 02 Jan 2014 09:36:05 AM
Having an SQL query will severely limit what you can do in the report. It means only locally processed items can be added unless you amend the SQL. I'd seriously consider replacing the SQL with a "normal" query if possible.

If each value in columns is a separate item, then things get quite complicated...

MF.
Title: Re: crosstab custom calculation
Post by: mprof on 05 Jan 2014 12:40:42 AM
I see, thanks, but unfortunately I cannot change to *normal*  query.
Title: Re: crosstab custom calculation
Post by: navissar on 05 Jan 2014 12:49:05 AM
Hey,
If (And for the life of me I cannot think of a fitting scenario) you cannot build the report on top of a package, then you'll have to amend the SQL - that is, add the calculation you need on the SQL level.
I would, however, recommend strongly that you find a way to create a framework package and build the report on top of that, for two reasons:
A. It's a crosstab. Cognos creates a small cube on server for Crosstabs, and it pulls the SQL results into it. It does this better when it can affect the SQL.
B. It will make for better performance and easier maintenance.