COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: kstevens67 on 17 Mar 2020 05:29:40 PM

Title: Newby question on calculating
Post by: kstevens67 on 17 Mar 2020 05:29:40 PM
I'm trying to calculate using Query Calculation the Hours worked divided by Total hours. For example: I have a sales rep with 7 hours and the total hours worked for every sales rep at this department is 50. these numbers appear in the same column with total on the bottom as usual.

([Sales Hours]/[Total(Sales Hours)])

What is happening is that both [Sales Hours] and [Total(Sales Hours)] equal 7, so I keep getting 1.

My columns look like this

Name          Sales Hours   Rate            Query Calc
Sue               7                $40              1
Joe                24              $33              1
Frank             19              $38              1
Total             50               $111            1

I want the calculation to be 7/50, 24/50, and 19/50 down that column

Would anyone kindly help and let me know what I am missing?

Thanks,




Title: Re: Newby question on calculating
Post by: seb24c on 18 Mar 2020 07:29:50 AM
Currently total is calculating just for each row, so you would need to change the calculation to:

( [Sales Hours] / Total( [Sales Hours] for report ) )

Or if there are multiple departments, and it should be total for each one, then:

( [Sales Hours] / Total( [Sales Hours] for [Dept] ) )
Title: Re: Newby question on calculating
Post by: kstevens67 on 18 Mar 2020 12:36:14 PM
Thank You! That worked like a charm!

Best,

K
Title: Re: Newby question on calculating
Post by: kstevens67 on 19 Mar 2020 12:14:48 PM
Hello again!

Looks like my client wants to multiply the total by the full report rate total. Can using multiple for options be combined in one statement? I keep getting an internal error trying to use what I learned in the last post.

I tried
( [Sales Hours] / Total( [Sales Hours] for [Dept] ) )  * Total([Sales Rate] for report )
and putting inside the parens.
( [Sales Hours] / Total( [Sales Hours] for [Dept] ) * Total([Sales Rate] for report ) ) 

Best,

K


Title: Re: Newby question on calculating
Post by: seb24c on 19 Mar 2020 02:56:43 PM
What is [Sales Rate]? If that's the existing calculation, then I'd expect it to error because it's trying to calculate using itself.

Assuming [Sales Rate] = [Sales Hours] / total ( [Sales Hours] for [Dept] ) then you'd need to include both full calculations from above:

( [Sales Hours] / total ( [Sales Hours] for [Dept] ) ) * ( [Sales Hours] / total ( [Sales Hours] for report ) )

I think that's what you're saying, but if not let me know!
Title: Re: Newby question on calculating
Post by: kstevens67 on 20 Mar 2020 01:25:16 PM
Hi seb,

Thank you for your response and help with this.

Sales Rate is actually the gross amount that sales rep made. Sales Hours is the amount of hours worked. I am trying to calculate two different columns together. I have tried a few things using the format you gave.

( [Sales Hours] / Total( [Sales Hours] for [Dept] ) ) * ( [Sales Hours] / Total( [Sales Hours] for report ) ) = This ran with no issues but not exactly what we need this time as this calculates using just the hours column.

( [Sales Hours] / Total( [Sales Hours] for [Dept] ) ) * ( [Sales Rate] / Total( [Sales Rate] for report ) ) = This gave an error when validating "SQL Created Circular reference"

I tried reversing the two.
( [Sales Rate] / Total( [Sales Rate] for report ) ) * ( [Sales Hours] / Total( [Sales Hours] for [Dept] ) ) = This gives another error when validating "Internal Error"


Best,

K


Title: Re: Newby question on calculating
Post by: seb24c on 23 Mar 2020 11:24:00 AM
I don't think I'm fully understanding. Is this what you expect to see, using the example data from above?


   
     
     
     
     
     
NameSales HoursRateHrs/Total HrsSales RateRate/Total RateHrs/Total Hrs * Rate/Total Rate
Sue7$40 7/50 (0.14)740740/50111 (0.014767217)0.00206741
Joe24$33 24/50 (0.48)24332433/50111 (0.048552214)0.023305063
Frank19$38 19/50 (0.38)19381938/50111 (0.038674143)0.014696174
Total50$1115011150111/50111