dbTalk Databases Forums  

AVG aggregate with zero (0) values

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss AVG aggregate with zero (0) values in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
DiGa
 
Posts: n/a

Default AVG aggregate with zero (0) values - 08-22-2005 , 04:00 AM






Hi,

I'm designing a very simple cube with the dimensions

- date (year, month)
- product group (group, sub group)
- company

and the measure

- turnover
- royalty rate (percent)

My goal is to have a calculated measure which indicates the royalty
rate on all levels correctly. Since the royalty percentage is defined
on the level of product SUB group, i need to have the average
percentage in case the user is not showing the level of product sub
group. I did the following:

1) Create calculated member "RateSum" = Sum([royalty rate])
2) Create calculated member "RateCount" = Count([royalty rate])
3) Create calculated member "RoyaltyRate" = [RateSum]/[RateCount]

So good for now. The problem I have is that there are product groups
with rate 0%, which leads to wrong average values.

In SQL i would run the expression AVG(NULLIF(Rate,0)) to deal with this
problem. Does anybody know how i can exclude certain values (in my case
the value "0") from being counted by the COUNT aggregate? Or do you
have another way how I could accomplish?

Your help is greatly appreciated!

Sincerely,
DiGa


Reply With Quote
  #2  
Old   
Jéjé
 
Posts: n/a

Default Re: AVG aggregate with zero (0) values - 08-22-2005 , 04:45 PM






you have to use a SQL formula like for the source column of your count
measure:

case when MyColumn > 0 then 1 else 0 end
(T-SQL syntax for SQL server)

use a sum aggregation instead-of a count.
so you'll summarize 0 & 1 values and you'll have the right count.


"DiGa" <dgasser (AT) ch (DOT) oetiker.com> wrote

Quote:
Hi,

I'm designing a very simple cube with the dimensions

- date (year, month)
- product group (group, sub group)
- company

and the measure

- turnover
- royalty rate (percent)

My goal is to have a calculated measure which indicates the royalty
rate on all levels correctly. Since the royalty percentage is defined
on the level of product SUB group, i need to have the average
percentage in case the user is not showing the level of product sub
group. I did the following:

1) Create calculated member "RateSum" = Sum([royalty rate])
2) Create calculated member "RateCount" = Count([royalty rate])
3) Create calculated member "RoyaltyRate" = [RateSum]/[RateCount]

So good for now. The problem I have is that there are product groups
with rate 0%, which leads to wrong average values.

In SQL i would run the expression AVG(NULLIF(Rate,0)) to deal with this
problem. Does anybody know how i can exclude certain values (in my case
the value "0") from being counted by the COUNT aggregate? Or do you
have another way how I could accomplish?

Your help is greatly appreciated!

Sincerely,
DiGa




Reply With Quote
  #3  
Old   
DiGa
 
Posts: n/a

Default Re: AVG aggregate with zero (0) values - 08-23-2005 , 01:01 AM



Very nice idea you came up with! Thank you very much for your help!


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.