I have two time dimensions, production period and accounting period, and a measure that I want to aggregate with either dimension but not with both when users query the cube from excel. To do that I created a flag measure to check if both dimensions are being used
CREATE MEMBER CURRENTCUBE.[Measures].[AcctProdFlag] AS
IIF (
[DIM Accounting Period].[Accounting Period Hierarchy].CURRENTMEMBER.level.ordinal <> 0 and
[DIM Production Period].[Production Month Hierarchy].currentmember.level.ordinal = 0 ,
1,
IIF ( [DIM Production Period].[Production Month Hierarchy].currentmember.level.ordinal <> 0 and
[DIM Accounting Period].[Accounting Period Hierarchy].currentmember.level.ordinal = 0 ,
2,
3
)
), VISIBLE =0;
Then I use this flag to create my measure as such
CREATE MEMBER CURRENTCUBE.[Measures].[Sales/day] AS
IIF([Measures].[AcctProdFlag] = 1 ,
([Measures].[Sales] / [Measures].[Accounting Period Day Count]),
IIF([Measures].[AcctProdFlag] = 2,
([Measures].[Sales] / [Measures].[Production Period Day Count]),
"NA")),
VISIBLE = 1, DISPLAY_FOLDER = 'Sales\Daily' , FORMAT_STRING = "#,###";
When I use this query from management studio, it works and returns "NA" as expected because both dimensions are being used
SELECT {[Measures].[Sales/day]} ON COLUMNS ,
[DIM Production Period].[Production Month].MEMBERS ON ROWS
FROM [My Cube]
WHERE {[DIM Accounting Period].[Accounting Year].[2014],
[DIM Accounting Period].[Accounting Year].[2015]};
But when I add accounting year to filter in excel and add production period in rows, the measure shows values (it shouldn't as per the logic) when I select multiple accounting years but shows "NA" (as expected) when I select one accounting year. Turns out that when I select multiple years, excel send the following query to SSAS causing it to loose the context
SELECT {[Measures].[Sales/day]} ON COLUMNS ,
[DIM Production Period].[Production Month].MEMBERS ON ROWS
FROM (SELECT (
{[DIM Accounting Period].[Accounting Year].[2014],[DIM Accounting Period].[Accounting Year].[2015]}
) ON COLUMNS
FROM [My Cube]
)
Is there anything I can do to fix this?. I am using SSAS for SQL Server 2008 R2 and Excel 2013.