Hi all,
As a follow up for my previous post about calculating the number of active subscriptions at any given moment (http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1147061&SiteID=1) an other 'newby question'.
With the measures from my previous post I managed to make two calculated members: [ Active subscriptions SoP] and [Active subscription EoP] (SoP = Start of Period; EoP = End of Period).
What I would like to create is an other member which calculates the average number of active subscriptions for a given period, so I can create an pivot like the one below. At the question marks ofcourse should be the average for the entire week. This however is not equal to (10843 + 10866) / 2 = 10854.5 but equals (10854 + 10858.285714) / 2 = 10856.142857. In other words the week average is not (SoP + EoP) / 2 but (Average SoP + Average EoP) / 2. Can someone please help me with the MDX expression I've to wirte to create this calculated member
Tabel:
| active subscriptions SoP | active subscriptions EoP | average active subscriptions | |||
| 2006 | Week 02, 2006 | Januari 16,2006 | 10843 | 10850 | 10846.5 |
| Januari 17,2006 | 10843 | 10850 | 10846.5 | ||
| Januari 18,2006 | 10850 | 10852 | 10851 | ||
| Januari 19,2006 | 10852 | 10858 | 10855 | ||
| Januari 20,2006 | 10858 | 10866 | 10862 | ||
| Januari 21,2006 | 10866 | 10866 | 10866 | ||
| Januari 22,2006 | 10866 | 10866 | 10866 | ||
| total | 10843 | 10866 |

Calculating the average over time
Mach1
Yes that is what I did:
Create member currentcube.[Measures].[Average subscriptions SoP] as
avg ( [Date Time].[Day].CurrentMember, [Measures].[Active subscriptions SoP] )
, visible=true;
leclerc9
Well, I am also a bit of a noob, so I can't help you much with it :(
-edit-
Of course, you get the same, if the granularity is the same
Adam Miles
http://msdn2.microsoft.com/en-us/library/aa902637(SQL.80).aspx
quote from the link:
JasonG271009
Just to try
ProjectDev
Hi all,
After a few hours playing with the different functions, measures and scopes I found a solution that I wanted to share with you guys. First of all I created a method for counting the number of days for the selected time-member. I use a recursive measure to accomplish this:
create member currentcube.[measures].[DayCount] as
sum
(
[Date Time].[Week hierarchy].CurrentMember.Children,
[Measures].[DayCount]
)
,visible=false;
SCOPE ([Measures].[DayCount]);
[Date Time].[Week hierarchy].[Day] = 1;
[Date Time].[Month hierarchy].[Month code] = sum([Date Time].[Month hierarchy].CurrentMember.Children, [Measures].[DayCount]);
[Date Time].[Month hierarchy].[Quarter] = sum([Date Time].[Month hierarchy].CurrentMember.Children, [Measures].[DayCount]);
END SCOPE;
I use two different hierarchies in my Date/Time dimension, that’s why the two last lines in the scope part are added.
Next I have to sum up all the active subscriptions at the start of the period (Active Subscriptions SoP), so I’ve created a measure that works almost the same way as the DayCount:
create member CurrentCube.[Measures].[Sum Subscriptions SoP] as
sum
(
[Date Time].[Week hierarchy].CurrentMember.Children,
[Measures].[Sum subscriptions SoP]
)
,visible=false;
SCOPE ([Measures].[Sum Subscriptions SoP]);
[Date Time].[Week hierarchy].[Day] = [Measures].[active subscriptions SoP];
[Date Time].[Month hierarchy].[Month code] = sum([Date Time].[Month hierarchy].CurrentMember.Children, [Measures].[Sum subscriptions SoP]);
[Date Time].[Month hierarchy].[Quarter]= sum([Date Time].[Month hierarchy].CurrentMember.Children, [Measures].[Sum subscriptions SoP]);
END SCOPE;
After this I only have to create a measure that takes the [Sum Subscriptions SoP] and divides it by [DayCount] :
create member currentcube.[Measures].[Average subscriptions SoP] as
[Measures].[Sum subscriptions SoP] / [Measures].[DayCount]
,visible=false;
I’ve created the same set of measures for the End of Period measures (Active Subscriptions EoP). To finish my [Average Subscriptions] measure I simply add both measures and divide them by 2:
create member currentcube.[Measures].[Average subscriptions] as
([Measures].[Average subscriptions SoP]+[Measures].[Average subscriptions EoP])/2
,visible=true;
vsnetdeveloper
Anyhow, here's maybe a usefull link:
http://www.databasejournal.com/article.php/1459531/
(scroll down until: MDX Essentials Series )
from:
http://www.mosha.com/msolap/mdx.htm
Bart Vercauteren
Yes there is an AVG(<<Set>>[, <<Numeric Expression>>]) but this gives some strange and unwanted results, maybe I'm missing something. When I create the member like this:
avg ( [Date Time].[Day].CurrentMember, [Measures].[Active subscriptions SoP] )
It will allways return the same value als [Measures].[Active subscriptions SoP], so I'm clearly missing the point here :)
I've read the articles you refer to, but I could not find the answer in there... That is, I'm probably to 'newby' to find it.
pangitko79
Yes that is of course true, but the week average is the same as the last day average and that is what is strange about it...
Pipz
Like with the following example:
from: http://www.mosha.com/msolap/articles/MDXForEveryone.htm