I am trying to better understand scopes and calculated members better, so in the AdventureWorks
database I did the following:
I wrote this simple scope statement:
SCOPE([Customer].[Customer].[All Customers], [Measures].[Average Rate]);
/* This expression sets the value of the Amount measure */
THIS = 999;
END SCOPE;
And equivalent calculated member will be this:
Create Member CurrentCube.[Measures].[My Measure]
AS
iif([Customer].[Customer].currentmember IS [Customer].[Customer].[All Customers], 999, [Measures].[Average Rate]);
But I am not sure how to create calculated member that will be equivalent to this scope assignment:
SCOPE([Customer].[Country].members, [Measures].[Average Rate]);
/* This expression sets the value of the Amount measure */
THIS = 999;
END SCOPE;
Actually I am not sure how to write iff
that will check if current member of Customer dimension is a member of [Customer].[Country]
Here you go
///Will Display 999 for any member apart from All
with Member [Measures].[My Measure]
AS
iif([Customer].[Country].currentmember.Properties ("Member_Value",TYPED)='All Customers',[Measures].[Internet Sales Amount] , 999)
select {[Measures].[Internet Sales Amount],[Measures].[My Measure]}
on columns,
[Customer].[Country].members
on rows
from [Adventure Works]
///Will display 999 for any member
with Member [Measures].[My Measure]
AS
iif([Customer].[Country].currentmember.Properties ("Member_Value",TYPED)='WhatEver', 999, 999)
select {[Measures].[Internet Sales Amount],[Measures].[My Measure]}
on columns,
[Customer].[Country].members
on rows
from [Adventure Works]
//Below queries help to check if a member is part of a hierarchy ///////////////////////////////////////////////////////////////////////////
//Query checks if a Member is part of a hierarchy
with MEMBER TestIFAValidMember
as
[Product].[Subcategory].[InvalidMember].UniqueName
MEMBER TestIFAValidMember2
as
[Product].[Subcategory].[Caps].UniqueName
select {TestIFAValidMember,TestIFAValidMember2}
on columns
FROM [Adventure Works]
You can also try
WITH MEMBER MEASURES.NotMember AS
IsSibling([Product].[Category].CURRENTMEMBER, [Product].[Category].[Invalid])
MEMBER MEASURES.ISMember AS
IsSibling([Product].[Category].CURRENTMEMBER, [Product].[Category].[Bikes])
SELECT {MEASURES.NotMember,MEASURES.ISMember} ON 0,
[Product].[Category].MEMBERS ON 1
FROM [Adventure Works]