Deepak,
Thanks for the post and solution.
Can you explain what is actually going on here:
Member [Measures].[Top4Share] as
'[Measures].[Unit Sales]/
Sum(Generate({[Product].CurrentMember} as CurProd,
Filter(MyInfo, [Product].CurrentMember is CurProd.Item(0).Item(0))),
[Measures].[Unit Sales])',
FORMAT_STRING = 'Percent'
As the percentage is figured out, for each member, what is the FILTER
function doing? What does the "[Product].CurrentMember is
CurProd.Item(0).Item(0)" do in this respect? What I'm having a hard
time understanding is, how is the product of the GENERATE (or
CROSSJOIN) iteriated through when the query is executed and how can we
use that SET in the MEMBER. How this question makes sense.
As I was trying, I found that what I have below also worked. What is
the better way to attack this problem. What are the performance
considerations that I should make.
MEMBER Measures.SumAtLevel AS ' Sum ( { TOPCOUNT (
[Customers].CurrentMember.Parent.CHILDREN , 4 , Measures.[Unit Sales] )
} , Measures.[Unit Sales] ) ' , SOLVE_ORDER = 100
MEMBER Measures.MyPercentage AS ' Measures.[Unit Sales] /
Measures.SumAtLevel ' , FORMAT_STRING = 'Percent'
My idea was to take the CurrentMember of the Customers (in our example
that you provided) and then get the parent of it and the top 4 children
(which would return the same items as the intial SET and sum them up.
Then this could be used for the Percentage for that level. The
complete query based on what you provided would be as follows (both
return same results):
With SET MyInfo AS
'GENERATE(
DESCENDANTS(Product, [Product].[Product Family]),
TOPCOUNT (NONEMPTYCROSSJOIN(
{[Product].CurrentMember},
DESCENDANTS (Customers , [Customers].[City])
), 4, [Measures].[Unit Sales]))'
Member [Measures].[Top4Share] as
'[Measures].[Unit Sales]/
Sum(Generate({[Product].CurrentMember} as CurProd,
Filter(MyInfo, [Product].CurrentMember is CurProd.Item(0).Item(0))),
[Measures].[Unit Sales])',
FORMAT_STRING = 'Percent'
MEMBER Measures.SumAtLevel AS ' Sum ( { TOPCOUNT (
[Customers].CurrentMember.Parent.CHILDREN , 4 , Measures.[Unit Sales] )
} , Measures.[Unit Sales] ) ' , SOLVE_ORDER = 100
MEMBER Measures.MyPercentage AS ' Measures.[Unit Sales] /
Measures.SumAtLevel ' , FORMAT_STRING = 'Percent'
select { Measures.SumAtLevel , Measures.MyPercentage ,
[Measures].[Unit Sales], [Measures].[Top4Share]} on 0,
Non Empty MyInfo on 1
from Sales
Thanks,
Pallav
Deepak Puri wrote:
Quote:
Here's a Foodmart Sales cube query, which lists the % share of each of
the Top 4 cities, for each Product Family:
With SET MyInfo AS
'GENERATE(
DESCENDANTS(Product, [Product].[Product Family]),
TOPCOUNT (NONEMPTYCROSSJOIN(
{[Product].CurrentMember},
DESCENDANTS (Customers , [Customers].[City])
), 4, [Measures].[Unit Sales]))'
Member [Measures].[Top4Share] as
'[Measures].[Unit Sales]/
Sum(Generate({[Product].CurrentMember} as CurProd,
Filter(MyInfo, [Product].CurrentMember is CurProd.Item(0).Item(0))),
[Measures].[Unit Sales])',
FORMAT_STRING = 'Percent'
select {[Measures].[Unit Sales], [Measures].[Top4Share]} on 0,
Non Empty MyInfo on 1
from Sales
- Deepak
Deepak Puri
Microsoft MVP - SQL Server
*** Sent via Developersdex http://www.developersdex.com *** |