Parameterised MDX query does not recognise parameters - reporting-services

I have an MDX Query in reporting services (built with query builder) which looks like this:
SELECT NON EMPTY { [Measures].[Injury Illness Cases] } ON COLUMNS
, NON EMPTY { ([DimI Gender].[Gender Text].[Gender Text].ALLMEMBERS
* [DimI State].[State Text].[State Text].ALLMEMBERS ) } DIMENSION
PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( STRTOSET(#DimIStateStateText, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT ( { [DimI Gender].[Gender Text].&[Female], [DimI Gender].[Gender Text].&[Male] } ) ON COLUMNS
FROM [US Census Final Injuries])) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR
, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
The problem is I used to have user-input, query-based parameter here (#DimIStateStateText) and the report used to run fine. I was, however, forced to changed it to free text parameter, and even when I type in the exact same value as it was shown before (e.g. Oklahoma) the reports doesn't return any data.
What is the cause of this? Can I provide the parameter without changing the whole query to dynamic string?

Related

SSRS - the restrictions imposed by the CONSTRAINED flag in the STRTOSET function were violated

I am new to SSRS, i make a report used three parameter FromDimDateDateKey,ToDimDateDateKey and InstrumentSName, and i got error that query execution failed for my DataSet and query (1,343) the restrictions imposed by the CONSTRAINED flag in the STRTOSET function were violated. what should i do ? anybody can help me ?
this is My MDX Query :
SELECT
NON EMPTY { [Measures].[Price] } ON COLUMNS,
NON EMPTY {
(
[DimDate].[Date Key].[Date Key].ALLMEMBERS *
[Dim Instrument].[Instrument Code].[Instrument Code].ALLMEMBERS *
[Dim Instrument].[Instrument S Name].[Instrument S Name].ALLMEMBERS
)
} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_VALUE, MEMBER_UNIQUE_NAME ON ROWS
FROM(
SELECT(
STRTOSET(
#DimInstrumentInstrumentSName,
CONSTRAINED
)
) ON COLUMNS
FROM(
SELECT(
STRTOMEMBER(#FromDimDateDateKey, CONSTRAINED):
STRTOMEMBER(#ToDimDateDateKey, CONSTRAINED)
) ON COLUMNS
FROM [CUBE_SIAPDW]
)
) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
It is telling you that this has failed:
STRTOSET(
#DimInstrumentInstrumentSName,
CONSTRAINED
)
If you check-out the documentation for strtoset: https://learn.microsoft.com/en-us/sql/mdx/strtoset-mdx
It says that CONSTRAINED is optional and:
When the CONSTRAINED flag is used, the set specification must contain
qualified or unqualified member names or a set of tuples containing
qualified or unqualified member names enclosed by braces {}. This flag
is used to reduce the risk of injection attacks via the specified
string. If a string is provided that is not directly resolvable to
qualified or unqualified member names, the following error appears:
"The restrictions imposed by the CONSTRAINED flag in the STRTOSET
function were violated."
So, if using constrained, the paramenter #DimInstrumentInstrumentSName will need to be a string something like this - note the curly brackets:
'{[Geography].[Geography].[Country].[Germany],[Geography].[Geography].[Country].[Canada]}'

SSRS Space Issue in Parameter Value

I am facing some issues with parameter in SSRS reports that when my Multi value parameter contains the space in between then I get the syntax error
If i choose any other parameter value which do not contains the space then it works well. I am using SSAS cube as a data source
WITH MEMBER [Measures].[PV] AS #Percentile
Member [Measures].[CntCT] as Count(NonEmpty(STRTOSET(#State) * [Tb Main].[UID].[UID].ALLMEMBERS,[Measures].[CPT1] ))
Member [Measures].[PVInt20] as Int(((([Measures].[CntCT] - 1)* [Measures].[PV])/100) - 1)
Member [Measures].[PVC] as
([Measures].[CPT1],Order(NonEmpty(STRTOSET(#State)*[Tb Main].[UID].[UID].ALLMEMBERS ,
[Measures].[CPT1]), [Measures].[CPT1],BASC).Item([Measures].[PVInt20]))
Select [Measures].[PVC] on columns, STRTOSET(#State) on rows from [POC 1];
Query works in query designer with both parameter and entire unique name i.e [Tb Main].[State Name].&[Wash DC]
Try changing the state parameter query to:
WITH
MEMBER [Measures].[ParamValue] as [Tb Main].[State Name].CurrentMember.UniqueName
SELECT { [Measures].[ParamValue] } ON COLUMNS,
NonEmpty ([Tb Main].[State Name].[State Name].ALLMEMBERS, [Measures].[CPT1] ) DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS FROM [POC 1]
Use the ParamValue column as the value property of the state parameter. Then your query downstream should work even when there are spaces.

How to create MDX parameters for SQL Server Reporting Services (SSRS)?

In SQL Server Reporting Service, when I connect to my cube to create a dataset, in Query Designer I create my query with a filter. It creates the following MDX for me:
SELECT NON EMPTY { KPIValue("KPI1"), KPIGoal("KPI1"), KPIStatus("KPI1") }
ON COLUMNS, NON EMPTY { ([Create Date].[Month Num].[Month Num].ALLMEMBERS * [Create Date].[Hierarchy].[Month].ALLMEMBERS ) }
DIMENSION PROPERTIES MEMBER_CAPTION,
MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT
( STRTOSET(#CreateDateYear, CONSTRAINED) )
ON COLUMNS FROM [ERP])
WHERE ( IIF( STRTOSET(#CreateDateYear, CONSTRAINED).Count = 1,
STRTOSET(#CreateDateYear, CONSTRAINED),
[Create Date].[Year].currentmember ) )
CELL PROPERTIES VALUE, BACK_COLOR,
FORE_COLOR, FORMATTED_VALUE,
FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
When I add this dataset, Reporting Services creates a parameter named CreateDateYear. When I pass a value like "2014" to this parameter I get nothing and I have to pass a value like [Create Date].[Year].&[2014].
How can I change my report to change this parameter for passing the value like "2014" instead of ugly and not user-friendly string [Create Date].[Year].&[2014]?
I did not change the MDX. In the Dataset Properties of my report I Changed the Parameter Value to:
="[Create Date].[Year].&[" + Parameters!Year.Value + "]"
And the problem solved
Use string concatenation to add the "prefix" '[Create Date].[Year].&[' and the "postfix" ']' in MDX:
STRTOSET('{ [Create Date].[Year].&[' + #CreateDateYear + '] }', CONSTRAINED)
if #CreateDateYear contains something like "2014".
Notes: I also added braces around the member unique name, as that is the proper syntax for a set in MDX. And if you would want to allow multiple selection, then probably it would be better to do the string concatenation in Reporting Services instead of MDX.

Parameter returns error because it was referenced in an inner subexpression

I've created a simple query in MDX to lookup a value. When i use this it works:
With
MEMBER [Measures].[dummy] as 1
select non empty {
[Measures].[dummy]
} on columns,
non empty {
except([Product].[Code].members, [Product].[Code].[All])
* except([Product].[Description].members, [Product].[Description].[All])
} on Rows
FROM
(SELECT Filter([Product].[Description].[Description].Members,
(InStr(1,[Product].[Description].CurrentMember.member_caption,"502080")>0))
ON COLUMNS
FROM [Cube])
but when i try to make this dynamic for use with MSRS it gives me an error:
"The SearchFor parameter could not be resolved because it was referenced in an inner subexpression"
This is my code with parameter:
With
MEMBER [Measures].[dummy] as 1
select non empty {
[Measures].[dummy]
} on columns,
non empty {
except([Product].[Code].members, [Product].[Code].[All])
* except([Product].[Description].members, [Product].[Description].[All])
} on Rows
FROM (
SELECT StrToMember
("Filter([Product].[Description].[Description].Members,
(InStr(1,[Product].[Description].CurrentMember.member_caption," + StrToMember(#SearchFor) + ")>0))")
on Columns
FROM [Cube])
Who knows how to get around this error? Please point me into the right direction.
Thanks in advance.
The way in which you use the parameter is as a simple string, not as a member reference. Hence, just leave away the StrToMember so that the FROM clause gets
FROM
(SELECT Filter([Product].[Description].[Description].Members,
(InStr(1,[Product].[Description].CurrentMember.member_caption, #SearchFor)>0))
ON COLUMNS
FROM [Cube])
It is difficult to check this without access to your cube.
However, to check the logic of the expression, you could issue a query like this:
WITH MEMBER Measures.[test0] as
#SearchFor
MEMBER Measures.[test1] as
InStr(1,[Product].[Description].CurrentMember.member_caption, #SearchFor) > 0
SELECT { Measures.[test0], Measures.[test1] } on columns,
{
[Product].[Description].[ABC],
[Product].[Description].[DEF],
[Product].[Description].[GHI],
[Product].[Description].[JKL]
} on rows
FROM [Cube]
You should replace the product list with some products really existing in your cube, some which fulfill the search criteria, and some that do not. Then you should be able to see True and False in the last column, depending if the match with the search criteria is successful or not. And the column to the left of it should display your search parameter in all rows.
It turned out my report would not show the data i retrieved with my MDX query. I started over with a new dataset:
With
MEMBER [Measures].[ParameterCaption] AS [Product].[Description].CURRENTMEMBER.MEMBER_CAPTION
MEMBER [Measures].[ParameterValue] AS [Product].[Description].CURRENTMEMBER.UNIQUENAME
MEMBER [Measures].[ParameterLevel] AS [Product].[Description].CURRENTMEMBER.LEVEL.ORDINAL
select {
[Measures].[ParameterCaption], [Measures].[ParameterValue], [Measures].[ParameterLevel]
} on columns,
EXCEPT([Product].[Description].MEMBERS,[Product].[Description].[All]) *
EXCEPT([Product].[Code].MEMBERS,[Product].[Code].[All])
ON ROWS
FROM ( SELECT FILTER ([Product].[Description].Members,
(InStr ([Product].[Description].CurrentMember.Name,
#SearchFor) <> 0)) ON COLUMNS FROM [Cube])
After adding a new tablix in my report the filter works as expexted. I still have no idea why my previous MDX wasn't working with the report.

SSRS Parse Error local report processing

Please I need your help 4 days i'm searching about solution for this error i have this code :
SELECT NON EMPTY { [Measures].[T POND], [Measures].[FACT TABLE Count],
[Measures].[disponibilite], [Measures].[POND], [Measures].[T] }
ON COLUMNS, NON EMPTY { ([DIM AXE GEO 2].[VILLLE].[VILLLE].ALLMEMBERS ) }
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM (
SELECT (
STRTOMEMBER("[dim_date_Debut].[PK_Date].&["+ Format(CDate(Parameters!FromDimDateDebutPKDate.Value),
"yyyy-MM-dd")+"T00:00:00]") : STRTOMEMBER("[dim_date_fin].[PK_Date_fin].&
["+Format(CDate(Parameters!ToDimDateDebutPKDate.Value),"yyyy-MM-dd")+"T00:00:00]"))
ON COLUMNS FROM [CubeDispo])
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
This is the error when i deploy
query execution failed for dataset 'dataset1' query(4,93) Parser: the syntax for '.' is incorrect
Thank you in advance
Is something wrong with your parameter replacement in SSRS? It looks like maybe they are not being passed down? When I change:
STRTOMEMBER("[dim_date_Debut].[PK_Date].&["+ Format(CDate(Parameters!FromDimDateDebutPKDate.Value),
"yyyy-MM-dd")+"T00:00:00]")
To
STRTOMEMBER("[dim_date_Debut].[PK_Date].&[2010-01-01T00:00:00]")
The syntax is fine.
Firstly, run SQL Server Profiler, do an Analysis Services trace and capture the MDX that is being sent to SSAS from SSRS.
If the "Parameters!ToDimDateDebutPKDate.Value" is still in the MDX, then check how your parameters are being assigned to the dataset.
I see you are doing string concatenation to form your query. Make sure you use = operation to tell RS that its not a static query but an expression.
For example if i use this as a query in query designer, i would get an error.
"Select * from table where col =" & Parameters!FromDimDateDebutPKDate.Value
while the same thing with = operator before it becomes an expression which RS would evaluate before sending it to SQL
="Select * from table where col =" & Parameters!FromDimDateDebutPKDate.Value