MDX passing variable as string to Item()
Question
I have my MDX query as follow:
with set SelectedEntity as '{Union({[Category].[Tertiary Category].Members}, {[Category].[Secondary Category].Members}).Item("Emails")}'
select Crossjoin({[Measures].[Reach]}, {[Age Group].[15-17], [Age Group].[18-24], [Age Group].[25-30], [Age Group].[31-35], [Age Group].[36-40], [Age Group].[40+]}) ON ROWS,
{[SelectedEntity]} ON COLUMNS
from [AppUsage]
where {[Country].[India]}*{[Date].[2011].[April]}*{[Panel].[Syndicate]}
Here in place of Item("Emails")
I want pass a variable something like this Item(${category})
. Hence my query should become something like this:
with set SelectedEntity as '{Union({[Category].[Tertiary Category].Members}, {[Category].[Secondary Category].Members}).Item(${category})}'
select Crossjoin({[Measures].[Reach]}, {[Age Group].[15-17], [Age Group].[18-24], [Age Group].[25-30], [Age Group].[31-35], [Age Group].[36-40], [Age Group].[40+]}) ON ROWS,
{[SelectedEntity]} ON COLUMNS
from [AppUsage]
where {[Country].[India]}*{[Date].[2011].[April]}*{[Panel].[Syndicate]}
But try to pass this category
variable to this query it gives me error as Failed to parse the query.
I am not getting where am going wrong? Is this the correct way to pass a variable in Item() as it needs the string.
Note: ${category}
variable value I am getting after selecting an entity into the Auto-complete field which I want to pass to the above query
EDIT:
When I pass the value 'Emails' for category variable in the query, i.e. in above Item(${category})
, in logs the same query becomes Item(Emails)
. But instead of this it should be something like this: Item("Emails")
.
I need to know how do I pass this variable as a string in my mondrian MDX query.
Solution
I got the solution for this.
The variable needed to be passed as Item("${category}")
. Hence my query will become:
with set SelectedEntity as '{Union({[Category].[Tertiary Category].Members}, {[Category].[Secondary Category].Members}).Item("${category}")}'
select Crossjoin({[Measures].[Reach]}, {[Age Group].[15-17], [Age Group].[18-24], [Age Group].[25-30], [Age Group].[31-35], [Age Group].[36-40], [Age Group].[40+]}) ON ROWS,
{[SelectedEntity]} ON COLUMNS
from [AppUsage]
where {[Country].[India]}*{[Date].[2011].[April]}*{[Panel].[Syndicate]}
where ${category}
is my variable.