dbTalk Databases Forums  

average in month

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


Discuss average in month in the microsoft.public.sqlserver.olap forum.



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

Default average in month - 09-22-2005 , 09:09 AM






I was wondering whether anyone can help me with a problem i have with
the average. I have to count (additive) average in Year.
Example:


Year Month Val Avg
2001 1 10 10
2001 2 20 15 (10+20)/2
2001 3 30 20 (10+20+30)/3
2001 4 40 25 (10+20+30+40)/4
2002 1 20 24 (10+20+30+40+20)/5
2002 2 45 27.5 (10+20+30+40+20+45)/6
2002 3 5 24.3 (10+20+30+40+20+45+5)/7

2,3,4,5,6,7... is the number of filtered(selected by user) month


Can anyone help me?


Reply With Quote
  #2  
Old   
Deepak Puri
 
Posts: n/a

Default Re: average in month - 09-24-2005 , 12:21 AM






This MDX query for the Foodmart Sales cube may help:

Quote:
With Member [Measures].[Cumulative Average] as
'Sum([Time].[Month].Members.Item(0):[Time].CurrentMember,
[Measures].[Store Sales])/
Sum([Time].[Month].Members.Item(0):[Time].CurrentMember,
[Measures].[Sales Count])', FORMAT_STRING = '0.00'
select {[Measures].[Store Sales], [Measures].[Sales Count],
[Measures].[Sales Average], [Measures].[Cumulative Average]} on columns,
Non Empty [Time].[Month].Members on rows
from Sales
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***


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

Default Re: average in month - 09-24-2005 , 01:59 AM



Thank you very much,
but I have to write a OWC query, so for example I can't use "Non Empty"
or "Select" syntax.
To count the filtered months (for average) I try with
"Count([DATE].[Month].Members)" but this doesn't work, this return all
months. I try also with "Count(StrToSet("Axis(0)")" but this give be
strange random values.

How can I solve the problem?
Thanks,
J.


Reply With Quote
  #4  
Old   
Deepak Puri
 
Posts: n/a

Default Re: average in month - 09-25-2005 , 06:45 PM



Not sure I understand the OWC issue, since you can set the MDX query
text for OWC - maybe someone else know more?


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #5  
Old   
Darren Gosbell
 
Posts: n/a

Default Re: average in month - 09-25-2005 , 11:34 PM



You should be able to use the just calculated member definition from the
previous answer -

Sum([Time].[Month].Members.Item(0):[Time].CurrentMember,
[Measures].[Store Sales])/
Sum([Time].[Month].Members.Item(0):[Time].CurrentMember,
[Measures].[Sales Count])

--
Regards
Darren Gosbell [MCSD]
<dgosbell_at_yahoo_dot_com>
Blog: http://www.geekswithblogs.net/darrengosbell

In article <1127545186.570956.325150 (AT) z14g2000cwz (DOT) googlegroups.com>,
jengiolo (AT) yahoo (DOT) it says...
Quote:
Thank you very much,
but I have to write a OWC query, so for example I can't use "Non Empty"
or "Select" syntax.
To count the filtered months (for average) I try with
"Count([DATE].[Month].Members)" but this doesn't work, this return all
months. I try also with "Count(StrToSet("Axis(0)")" but this give be
strange random values.

How can I solve the problem?
Thanks,
J.




Reply With Quote
  #6  
Old   
jengi
 
Posts: n/a

Default Re: average in month - 09-26-2005 , 02:16 AM



The calculated member:
"Sum([Time].[Month].Members.Item(0):[Time].CurrentMember,[Measures].[Store
Sales])"
looks ok for me, but it give me this error:
"not valid levels (not correspondents) in the function Range"
What's the problem?
Thanks all
j.


Reply With Quote
  #7  
Old   
Darren Gosbell
 
Posts: n/a

Default Re: average in month - 09-26-2005 , 02:47 AM



Probably has to do with the second part of the time range not specifying
a level.

Quote:
[Time].[Month].Members.Item(0):[Time].CurrentMember
You could try, the following, but it may not work if you do not have the
month level in your select statement.

[Time].[Month].Members.Item(0):[Time].[Month].CurrentMember

Or you could try something like the range below to try and get the range
for the current level.

[Time].currentmember.level.Members.Item(0):[Time].CurrentMember

I have not tested either of these they are just off the top of my head,
but hopefully you can see the logic I am following.

--
Regards
Darren Gosbell [MCSD]
<dgosbell_at_yahoo_dot_com>
Blog: http://www.geekswithblogs.net/darrengosbell

In article <1127719008.632860.12220 (AT) o13g2000cwo (DOT) googlegroups.com>,
jengiolo (AT) yahoo (DOT) it says...
Quote:
The calculated member:
"Sum([Time].[Month].Members.Item(0):[Time].CurrentMember,[Measures].[Store
Sales])"
looks ok for me, but it give me this error:
"not valid levels (not correspondents) in the function Range"
What's the problem?
Thanks all
j.




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.