dbTalk Databases Forums  

Calculate average age when persons are not unique

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


Discuss Calculate average age when persons are not unique in the microsoft.public.sqlserver.olap forum.



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

Default Calculate average age when persons are not unique - 07-21-2006 , 08:04 AM






I have a employee-cube where each person can have more than one
employments. I have a distinct count measure for counting distinct
persons and an Age measure.
But how can I calculate the average age of employees? I can't just sum
the ages and divide by number of distinct persons since each person can
have more than employment. It wouldn't be correct to divide by number
of employments either.
E.g.

Person,Employment,Age
----------------------------------------
Person1,Employment1,20
Person1,Employment2, 20
Person2,Employment1, 80

The correct age average is 50 (100/2).
It would seem like simple enough, but I can't figure out how to solve
this in MDX

Any hints?

Thanks


Reply With Quote
  #2  
Old   
Magnus
 
Posts: n/a

Default Re: Calculate average age when persons are not unique - 07-21-2006 , 10:13 AM






Think I found a solution after all:

Aggragate function Max on the age measure

Then did the calculation Average age as:
Avg(NonEmptyCrossJoin([Person Unique].[Person
Unique].Members,{[Measures].[Distinct Persons]}),[Measures].[Maxage])

Seems to give the result I want, have to test it a bit further though.

/Magnus

Magnus skrev:

Quote:
I have a employee-cube where each person can have more than one
employments. I have a distinct count measure for counting distinct
persons and an Age measure.
But how can I calculate the average age of employees? I can't just sum
the ages and divide by number of distinct persons since each person can
have more than employment. It wouldn't be correct to divide by number
of employments either.
E.g.

Person,Employment,Age
----------------------------------------
Person1,Employment1,20
Person1,Employment2, 20
Person2,Employment1, 80

The correct age average is 50 (100/2).
It would seem like simple enough, but I can't figure out how to solve
this in MDX

Any hints?

Thanks


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.