passing parameters in MDX query in SSRS report
hi all,
A report uses a parameter say 'X'. It has 3 values in dropdown say X1,X2 and X3.The parameters are mapped on or passed to a particular column in the database say S1,S2 and S3 using a dataset, that uses MDX query. Please let me know how to pass/map the report
parameter value to the database parameter value. in general how to pass strings in MDX queries?
January 18th, 2011 4:27am
You need to write dynamic query in your MDX query Dataset. eg:
" SELECT .... Dimension.[" & Parameters!XYZ.Value & "] on rows fROM CUBE"
Free Windows Admin Tool Kit Click here and download it now
January 18th, 2011 7:34am
Hi,
We suggest using the function
STRTOSET OR
STRTOMEMBER. But actually, you don’t need to learn MDX, query designer can auto-generate parameter embed MDX query. You just need to select the Parameter Option in filter area. More information, you can refer to:
http://social.msdn.microsoft.com/Forums/en-US/sqlanalysisservices/thread/556935d2-bc72-4188-b0e5-eeff9241f56a/
Hope this helps,
RaymondRaymond Li - MSFT
January 19th, 2011 7:35am
hi,
The MDX query contains a statement like the following
ON
COLUMNS
FROM (
SELECT ([S].&[S1],[s].&[s2]))
where as the report layout has a filter which says
fields!S.value=IIF(Parameters!X.Value =
"X1","S1",IIF(Parameters!X.Value
= "X2","S2",fields!S.value))
I doubt if X1,X2 values arent mapped properly to S1 and S2. How to go about solving this?? should i include any string function?
Free Windows Admin Tool Kit Click here and download it now
January 19th, 2011 11:35pm
Here is an example, suppose this is your query:
select {[Measures].[Internet Order Quantity]} on 0,
[Product].[Category].[Category] on 1
from [Adventure Works]
where [Date].[Calendar Year].&[2002]
You can modify it like this:
select {[Measures].[Internet Order Quantity]} on 0,
[Product].[Category].[Category] on 1
from [Adventure Works]
where strtomember(@P1)
Now, if you pass the value [Date].[Calendar Year].&[2002] to the P1, then it will run just like:
where [Date].[Calendar Year].&[2002]
You can improve this by a parameter dataset, but I would still suggest you check how SSRS handle this, I mean it can generate MDX for you
automatically.
Hope this helps,
RaymondRaymond Li - MSFT
January 20th, 2011 12:44am
In case am not using date parameter, should i be using STRTOSET function Raymond?
Free Windows Admin Tool Kit Click here and download it now
January 20th, 2011 1:35am
Yes, you can always use STRTOSET, the difference is that STRTOSET returns a set not a member, so if it's mutiple-valued parameter, then you have to use STRTOSET.
Thanks,
RaymondRaymond Li - MSFT
January 20th, 2011 9:11pm
hi i tried changing the MDX query but the fields are no longer visible in dataset query. how to create the fields??
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2011 1:29am
The parameter used in the report is called "TrainAssingment" and it has 3 values. "LSOP" "IOP" and "ALL". There is a dimension called WOTrainCategory in the cube and the parameter values are mapped to the column called "train category code" in
the dimension.The following is the MDX query used in the dataset. Please guide me as to how to change the query to actually map the parameter value to the train category code.
SELECT
NON
EMPTY { [Measures].[Work Order Item Count] }
ON
COLUMNS,
NON
EMPTY { ([Dim Service Area- Control Area- Arriving Station].[Division].[Division].ALLMEMBERS
* [Dim Service Area- Control Area- Arriving Station].[Service Area].[Service Area].ALLMEMBERS * [Dim Service
Area- Control Area- Arriving Station].[TYES Control Area].[TYES Control Area].ALLMEMBERS * [Dim Service Area-
Control Area- Arriving Station].[Station Name].[Station Name].ALLMEMBERS * [Dim Service Area- Control Area- Arriving
Station].[FSAC CD].[FSAC CD].ALLMEMBERS * [Dim Work Order].[TYES TRAIN NM].[TYES TRAIN NM].ALLMEMBERS
* [Dim Work Order Item].[TYES CNDCTR ID].[TYES CNDCTR ID].ALLMEMBERS * [Dim Party Location].[LGLNT LCTN NM].[LGLNT
LCTN NM].ALLMEMBERS * [Dim Work Order Item].[ACTUAL TRACK RLTV SQNC NBR].[ACTUAL TRACK RLTV SQNC NBR].ALLMEMBERS
* [Dim Work Order Item].[ACTUAL INDSTR RLTV SQNC NBR].[ACTUAL INDSTR RLTV SQNC NBR].ALLMEMBERS * [Dim Not Done
Reason].[Customer Caused Code].[Customer Caused Code].ALLMEMBERS * [Dim Not Done Reason].[Description].[Description].ALLMEMBERS
* [Load Empty Status].[Load Empty Status].[Load Empty Status].ALLMEMBERS * [Dim Work Order Item].[ACTION TMS].[ACTION
TMS].ALLMEMBERS * [Dim Work Order Item].[EXTRA WORK DSCRPT TXT].[EXTRA WORK DSCRPT TXT].ALLMEMBERS
* [Dim WO Final Execution Date].[CLNDR DT].[CLNDR DT].ALLMEMBERS *
[Dim WO Train Category].[Train Category Code].[Train Category Code].ALLMEMBERS
* [Dim Service Area- Control Area- Customer Station].[FSAC CD].[FSAC CD].ALLMEMBERS * [Dim Service Area-
Control Area- Customer Station].[Station Name].[Station Name].ALLMEMBERS * [Dim Work Order].[INBND TMS].[INBND
TMS].ALLMEMBERS * [Dim Work Order Item].[ACTION TRACK SHORT ENGLSH NM].[ACTION TRACK SHORT ENGLSH NM].ALLMEMBERS
* [Dim Party Location].[LGLNT LCTN ID].[LGLNT LCTN ID].ALLMEMBERS ) }
DIMENSION
PROPERTIES
MEMBER_CAPTION,
MEMBER_UNIQUE_NAME
ON
ROWS
FROM (
SELECT ( -{ [Dim Work Order Item].[Fact Train Work Order Item].&[-1.] } )
ON
COLUMNS
FROM (
SELECT ( { [Dim Not Done Reason].[Customer Caused Code].&[N], [Dim Not Done Reason].[Customer Caused Code].&[Y]
} ) ON
COLUMNS
FROM (
SELECT ( { [Dim WO Train Category].[Train Category Code].&[L], [Dim WO Train Category].[Train
Category Code].&[R], [Dim WO Train Category].[Train Category Code].&[Y] } )
ON
COLUMNS
FROM (
SELECT (
STRTOSET(@DimPartyLocationLGLNTLCTNNM,
CONSTRAINED) )
ON
COLUMNS
FROM (
SELECT (
STRTOSET(@DimServiceAreaControlAreaCustomerStationStationName,
CONSTRAINED) )
ON
COLUMNS
FROM (
SELECT (
STRTOSET(@DimServiceAreaControlAreaArrivingStationStationName,
CONSTRAINED) )
ON
COLUMNS
FROM (
SELECT (
STRTOSET(@DimServiceAreaControlAreaArrivingStationTYESControlArea,
CONSTRAINED) )
ON
COLUMNS
FROM (
SELECT (
STRTOSET(@DimServiceAreaControlAreaArrivingStationServiceArea,
CONSTRAINED) )
ON
COLUMNS
FROM (
SELECT (
STRTOSET(@DimServiceAreaControlAreaArrivingStationDivision,
CONSTRAINED) )
ON
COLUMNS
FROM (
SELECT (
STRTOMEMBER(@FromDimWOFinalExecutionDateCLNDRDT,
CONSTRAINED) :
STRTOMEMBER(@ToDimWOFinalExecutionDateCLNDRDT,
CONSTRAINED) )
ON
COLUMNS
FROM [AIR]))))))))))
CELL
PROPERTIES
VALUE,
BACK_COLOR,
FORE_COLOR,
FORMATTED_VALUE,
FORMAT_STRING,
FONT_NAME,
FONT_SIZE,
FONT_FLAGS
Have highlighted the important part in the query.
The filter used in the report layout is the following
Fields!Train_Category_Code.Value
=IIF(Parameters!TrainAssignment.Value =
=IIF(Parameters!TrainAssignment.Value =
"LSOP","L",IIF(Parameters!TrainAssignment.Value
= "IOP","R",Fields!Train_Category_Code.Value))
January 21st, 2011 2:06am