问题
I have been looking all over stackoverflow for this and I can't figure it out. So I have a dataset using a SSAS cube, and it has two parameters. It has a category and subcategory.
I already created the datasets to populate these parameters and they work fine when I select them both.
The way my report runs is that it is a collection of subreports in a table and it is grouped by the category and sub grouped by the subcategory. So When I select the category parameter, it lists each sub category for all the sub reports.
What I am trying to do is getting a total of all the subcategories within that category. I tried using default values to ALL but doesnt work. I tried doing a total on the group within the table but that doesn't work.
So for Group G1 and subgroup SG1 and SG2), and sub reports SR1, SR2, it goes like this
G1
-TOTAL (SG1+SG2+SG3)
---SR1
---SR2
-SG1
---SR1
---SR2
-SG2
---SR1
---SR2
I was able to pull off the Sub group reports parts by setting the category parameter in the sub reports as the parameter passed in for the category, and the sub category parameter as the value of the sub group. But I need that darn total.
The MDX for My Category is
SELECT { } ON COLUMNS, { ([Service].[Category].[Category].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Sales-Cube] CELL PROPERTIES VALUE
The MDX for sub category is
SELECT { } ON COLUMNS, { ([Service].[Category].[Category].ALLMEMBERS * [Service].[SubCategory].[Subcategory].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Sales-Cube] CELL PROPERTIES VALUE
The MDX for the dataset I am using the parameters are was created using designer and it is as follows
SELECT NON EMPTY { [Measures].[Sales Count] } ON COLUMNS,
NON EMPTY { ([Date].[Fiscal Year].[Fiscal Year].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( Filter( [Service].[SubCategory].[SubCategory].ALLMEMBERS, Instr( [Service].[SubCategory].currentmember.Properties( 'Member_Caption' ), @ParamSubCategory ) > 0 ) ) ON COLUMNS
FROM ( SELECT ( Filter( [Service].[Category].[Category].ALLMEMBERS, Instr( [Service].[Category].currentmember.Properties( 'Member_Caption' ), @ParamCategory ) > 0 ) ) ON COLUMNS
FROM [Sales-Cube])) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
So based on what is selected from the category, it will filter the subcategory to only those within the category so it cascades. Any resources or help would be great.
回答1:
As I said in comments you cannot use the Name of your member to slice your cube in MDX, you have to use the unique name instead. You have to handle it so when your user selects Category X
and Category Y
for your ParamCategory
parameter, it should be set to [Service].[Category].&[Category X]
and [Service].[Category].&[Category Y]
. This is what I'd do.
I'd use an MDX script that returns label (Name) and unique name for populate Category.
WITH MEMBER [Measures].[Category Label] AS
[Service].[Category].CurrentMember.Name
MEMBER [Measures].[Category UniqueName] AS
[Service].[Category].CurrentMember.UniqueName
SELECT
{ [Measures].[Category Label], [Measures].[Category UniqueName] } ON COLUMNS,
{} ON ROWS
FROM [Sales-Cube]
In parameter properties / available values you have to use Category Label
field for Label field
and Category UniqueName
for Value field
.
The same apprach to populate ParamSubcategory
.
WITH MEMBER [Measures].[SubCategory Label] AS
[Service].[SubCategory].CurrentMember.Name
MEMBER [Measures].[SubCategory UniqueName] AS
[Service].[SubCategory].CurrentMember.UniqueName
SELECT
{ [Measures].[SubCategory Label], [Measures].[SubCategory UniqueName] } ON COLUMNS,
{ [Service].[SubCategory].[SubCategory] } ON ROWS
FROM [Sales-Cube]
WHERE ( StrToSet ( @ParamCategory ) )
Note I am using ParamCategory
to populate the ParamSubcategory
only with the related subcategories.
Now you can use those parameters in your MDX script:
SELECT NON EMPTY { [Measures].[Sales Count] } ON COLUMNS,
NON EMPTY
{
( [Date].[Fiscal Year].[Fiscal Year].AllMembers )
} Dimension Properties MEMBER_CAPTION,
MEMBER_UNIQUE_NAME ON ROWS
FROM (
SELECT ( STRTOSET( @ParamSubcategory ) ) ON COLUMNS
FROM (
SELECT ( STRTOSET ( @ParamCategory ) ) ON COLUMNS
FROM [Sales-Cube]
)
) CELL Properties Value,
BACK_COLOR,
FORE_COLOR,
FORMATTED_VALUE,
FORMAT_STRING,
FONT_NAME,
FONT_SIZE,
FONT_FLAGS
Note Filter
and InStr
function are not requerid since you are passing the unique name members.
It is not tested but should work, good luck!
Let me know if this helps.
来源:https://stackoverflow.com/questions/39371875/mdx-ssrs-parameter-category-chooses-all-sub-category