How to pass MultiSelect parameter from SSRS to MDX?
I tried as below which is not working as expected:
WHERE ({IIF( STRTOSET(#Name, CONSTRAINED).Count = 1,
STRTOSET(#Name, CONSTRAINED), [Name].currentmember )})
You can use directly :
WHERE ( STRTOSET(#Name, CONSTRAINED) )
or (not sure about this ) :
WHERE ( IIF( STRTOSET(#Name, CONSTRAINED).Count = 1,
STRTOSET(#Name, CONSTRAINED),
STRTOMEMBER(#Name, CONSTRAINED) ) )
However SSAS and set slicers are not always good friends. If possible use MDX Subselects instead :
WHERE ( SELECT STRTOSET(#Name, CONSTRAINED) ON 0 FROM .. )
Related
I have an SSRS parameter that allows to select multiple values of type varchar.
How can I get my where clause to show all those selected in the parameter. An example is if the parameter choices were
1 : Rob
2 : Tom
3 : Rick
If the first two choices were selected, there should be 2 records. Something to the effect:
where Employee.Code + ' : ' + Employee.Name IN ("1 : Rob","2 : Tom")
If the parameter value is returning both the "employee code" and "employee name", then I'd use a CTE (Common Table Expression) to create the concatenated column before filtering it. You may want to create the CTE in a view if you're going to use it elsewhere.
WITH
employee
AS
(
SELECT tbl.* FROM (VALUES
( 1, 'Rob')
, ( 2, 'Tom')
, ( 3, 'Rick')
) tbl ([code], [name])
)
,
employee_values
AS
(
SELECT
[code]
, [name]
, [code_name] = CAST([code] AS VARCHAR) + ' : ' + [name]
FROM
employee
)
SELECT
[code]
, [name]
, [code_name]
FROM
employee_values
WHERE
[code_name] IN(#Employee_Code)
I am trying to get previous month data for my SSRS report.But i am not getting any result.Could you please give any help.Below is my query.
SELECT
NON EMPTY
{[Measures].[Trade Net Amount]} ON COLUMNS
,NON EMPTY
{
[Fund].[Fund Name].[Fund Name].ALLMEMBERS*
[Transaction Type].[Transaction Description].[Transaction Description].ALLMEMBERS*
[Calendar Day].[Year].[Year].ALLMEMBERS*
[Calendar Day].[Month].[Month].ALLMEMBERS
}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM
(
--FROM ( SELECT ( STRTOSET(#CalendarDayMonth, CONSTRAINED) ) ON COLUMNS
--FROM ( SELECT ( STRTOSET(#CalendarDayYear, CONSTRAINED) ) ON COLUMNS
SELECT
StrToMember
(
"[Calendar Day].[Calender Hierarchy].[Month].[" + Format(Now(),"yyyy")
+
Format
(
Now()
,"MMM"
)
+ "].PrevMember"
) ON COLUMNS
FROM [Escher_Hybrid]
);
I am running the following command for getting a multi value report
StrToSet
("[Dim Branch].[HierarchyB-T-C].[Trading Code].&[" +
Replace(
Join(
Parameters!TradingName.Value,"],"
) +"]",",",",[Dim Branch].[HierarchyB-T-C].[Trading Code].&["),",")
But I'm getting an error
'The Syntax for 'Join' is incorrect'.
I don't know what I am doing wrong. Can anyone correct me please?
If I change it to StrToSet(#TradingName, Constrained) it works for single value, but I'd like to pass multiple values.
Do you need curly braces to form a set? I have added one at the start of the below ... a little unsure where the end of your string is - does it end like this .&["?!
StrToSet(
"{[Dim Branch].[HierarchyB-T-C].[Trading Code].&["
+
Replace(
Join(Parameters!TradingName.Value,"],") + "]"
, ","
, ",[Dim Branch].[HierarchyB-T-C].[Trading Code].&["
)
,","
)
If Parameters!TradingName.Value is equal to a string of this format MEC,RSA then maybe join is not required:
StrToSet(
"{"
+
Replace(
"[Dim Branch].[HierarchyB-T-C].[Trading Code].&["
+
Parameters!TradingName.Value
, ","
,"],[Dim Branch].[HierarchyB-T-C].[Trading Code].&["
)
+
"]}"
,constrained)
To pass multiple value from parameter, i just followed the steps
1 Add parameters and name it like
Under dataset properties (shared dataset properties as well) , the Parameters tab write an expression like this way
=Split(Parameters!TradingName.Value,",")
in Shared dataset, write the MDX with WHERE (StrToSet(#TradingName))
SELECT
{[Total]} ON COLUMNS
,
{
[Dim Account].[Account Type].&[Income]
}
*
STRTOMEMBER("[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[" + #FiscalYear +"]&[" + FORMAT(Now(),"MMMM") +"].PREVMEMBER")
*
ORDER
(
{
[Dim Branch].[Branch Name].[Branch Name]
},[Total], BDESC
)
ON ROWS
from [CubeProfitLoss]
WHERE (StrToSet(#TradingName))
when you want to preview the multiple value, make sure you are using , to separate trading name likewise
Is it possible to build a case statement (or equivalent) in MDX query to group together dimensional members based on parameter input from SSRS?
Below is a query showing roughly what I am trying to achieve (parameters have been commented out and hardcoded for testing) I'm afraid that I'm fairly new to mdx;
WITH
--PERIOD FOR COMPARISON BLOCK
SET [MonthNumber] AS
(
STRTOSET("[Date Procurement Created].[Month Number].&[9]"
--#DimCalendarMonthNumber
, CONSTRAINED)
)
--CONDITIONAL CASE BLOCK
SET [SelectedSuppliers] AS
CASE [Dim Supplier].[Supplier Name].CurrentMember
WHEN STRTOSET("[Dim Supplier].[Supplier Name].&[Flannels Direct Co Ltd],[Dim Supplier].[Supplier Name].&[Zucchini Trading Co]"
--#DimSupplierSupplierName
, CONSTRAINED)
THEN [Dim Supplier].[Supplier Name].CurrentMember
ELSE 'Other'
END
--CURRENT PERIOD BLOCK
MEMBER [Measures].[CP_LineTotal]
AS SUM(
([Measures].[Line Total],[MonthNumber])
), FORMAT_STRING = 'Currency'
--MAIN QUERY BLOCK
SELECT {
[Measures].[Line Total]
, [Measures].[CP_LineTotal]
}
ON 0,
NON EMPTY (
[SelectedSuppliers]
*[Dim Supplier].[AC Number].[AC Number].MEMBERS
*[Date Procurement Created].[Year Name].[Year Name].MEMBERS
)
ON 1
FROM
[TRANSACTION_PROCUREMENT]
I think this part of your code could change to the following:
SET [SelectedSuppliers] AS
IIF(
[Dim Supplier].[Supplier Name].CurrentMember
IS [Dim Supplier].[Supplier Name].&[Flannels Direct Co Ltd],[Dim Supplier].[Supplier Name].&[Zucchini Trading Co]
,[Dim Supplier].[Supplier Name].CurrentMember
,'Other'
)
IIF should always be used rather than CASE if possible.
Use the IS operator to compare members.
Also no need to use Sum in your definition of the measure as a simple tuple will suffice:
MEMBER [Measures].[CP_LineTotal] AS
([Measures].[Line Total],[MonthNumber])
, FORMAT_STRING = 'Currency'
I'm struggling to figure this one out and was hoping someone out there might be able to help.
I have an SSRS (2008) report that connects directly to an SSAS OLAP Cube. I have 5 different columns, each showing a different measure, broken out by the "Manager" dimension. I also have parametrized dropdowns in SSRS that filter the data based on various things.
Here's the code that got me to this point:
SELECT
NON EMPTY{
[Measures].[Metric A]
,[Measures].[Metric B]
,[Measures].[TMetric C]
,[Measures].[Metric D]
,[Measures].[Metric E]
} ON COLUMNS
,NON EMPTY{
([Ops Hierarchy].[Manager].[Manager].ALLMEMBERS )
} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM
(
SELECT
(
STRTOSET(#CompleteDateCalendar, CONSTRAINED) ) ON COLUMNS
FROM
(
SELECT
(
STRTOSET(#City, CONSTRAINED) ) ON COLUMNS
FROM
(
SELECT
(
STRTOSET(#Region, CONSTRAINED) ) ON COLUMNS
FROM
(
SELECT
(
STRTOSET(#Country, CONSTRAINED) ) ON COLUMNS
FROM
[CUBE]
)
)
)
)
WHERE
(
IIF( STRTOSET(#Country, CONSTRAINED).Count = 1, STRTOSET(#Country, CONSTRAINED)
, [Ops Hierarchy].[Division Name].currentmember )
, IIF( STRTOSET(#Region, CONSTRAINED).Count = 1, STRTOSET(#Region, CONSTRAINED)
, [Ops Hierarchy].[Region Name].currentmember )
, IIF( STRTOSET(#City, CONSTRAINED).Count = 1, STRTOSET(#City, CONSTRAINED)
, [Ops Hierarchy].[System Name].currentmember )
, IIF( STRTOSET(#CompleteDateCalendar, CONSTRAINED).Count = 1, STRTOSET(#CompleteDateCalendar, CONSTRAINED)
, [CompleteDate].[Calendar].currentmember )
)
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
And of course, SSRS automagically created the corresponding dropdowns for each #parameter.
Now, here's where I need help:
I have a new requirement to add a "Rank" column for each metric. So, for example, next to the "Metric A" column, there will be another column called "Metric A Rank" that ranks the manager on that row against the other managers that are showing on the report (based on the parameters selected in the dropdowns).
Now, I know that I can add:
WITH
SET [OrderedSet1] AS ORDER(FILTER([Ops Hierarchy].[Manager].MEMBERS,[Measures].[Metric A] <> NULL),[Measures].[Metric A],BASC)
MEMBER [Measures].[Metric A Rank] AS RANK([Ops Hierarchy].[Manager].CurrentMember,[OrderedSet1])
SET [OrderedSet2] AS ORDER(FILTER([Ops Hierarchy].[Manager].MEMBERS,[Measures].[Metric B] <> NULL),[Measures].[Metric B],BASC)
MEMBER [Measures].[Metric B Rank] AS RANK([Ops Hierarchy].[Manager].CurrentMember,[OrderedSet2])
etc, to the top of the MDX query, and then reference [Measures].[Metric A Rank] and [Measures].[Metric B Rank] in my select statement.
What I don't know how to do is filter the sets with the SSRS dropdowns so that I'm ranking against only what is showing on the report.
So for example, if someone has Country="USA", Region = "South", City = "Atlanta" and CompleteDate = "Jan 2012" selected in SSRS, and I rank Metric A against OrderedSet1, then I only want to show how each manager ranks against other managers in Atlanta for Jan 2012.
How do I "parameterize" the sets in the WITH clause using the SSRS dropdowns so that I'm only ranking against the subset that the user has selected?
Thanks in advance for your help!
in Set declaration you can use
SET [OrderedSet1] AS ORDER(FILTER([Ops Hierarchy].[Manager].MEMBERS*
[Ops Hierarchy].[System Name].currentmember
,[Measures].[Metric A] <> NULL),[Measures].[Metric A],BASC)