Search code examples
sql-serverssasmdxolap-cube

MDX where clause vs From clause


I do not understand why I do not get the same result between these 2 codes below :

I have a date dimension with a year attribute composed of members: 2016, 2017, 2018 and 2019

Code 1 :

with
Member [Measures].[MembersInWhereClause] AS
SETTOSTR(EXISTING([Dim Date].[Calendar].[Year].members))

select [Measures].[MembersInWhereClause] on 0
from [ODGG2Vente]
WHERE ([Dim Date].[Calendar].[Year].&[2018]:[Dim Date].[Calendar].[Year].&[2019])

I get as a result this set : "2018 and 2019". It works well !

Code 2

with
Member [Measures].[MembersInFromClause] AS
SETTOSTR(EXISTING([Dim Date].[Calendar].[Year].members))

select [Measures].[MembersInFromClause] on 0
FROM 
(
    SELECT (
    {[Dim Date].[Calendar].[Year].&[2018]
    ,[Dim Date].[Calendar].[Year].&[2019]}
    ) ON 0  
    FROM [ODGG2Vente]
)

I get as a result this set : "2016,2017,2018,2019" ??? I was hoping to get only the members specified in the from clause...

Thanks for your help


Solution

  • Finally, i found a solution using a named set. It works ! It can read the context of my subcube

    dynamic set [FirstMemberInASet] as
    EXISTS([Dim Date].[Calendar].[Month],EXISTING([Dim Date].[Calendar]. 
    [Date].members)).item(0)
    Member [Measures].[FirstMember] as
    SETTOSTR([FirstMemberSet])
    

    I obtain this result with a subcube :

    {[Dim Date].[Calendar].[Month].&[1]&[2018]}
    

    But the problem i need a member because i have to used parallelperiod.

    Is it possible to convert a set containing a single value {[Dim Date].[Calendar].[Month].&[2018]}

    to a member like this :

    [Dim Date].[Calendar].[Month].&[1]&[2018] ?
    

    Thx for ur help