Order by dimension mdx - reporting-services

I have this MDX:
WITH MEMBER [Measures].[InventarioSobreVentas] AS [Measures].[InventarioDirecto_Monto]/[Measures].[VentasInventarioDirecto_Ventas]*100 SELECT NON EMPTY {
[Measures].[InventarioDirecto_Monto],
[Measures].[VentasInventarioDirecto_Ventas], [Measures].[InventarioSobreVentas] } ON COLUMNS, NON EMPTY { (
[Dim_Tiempo_].[Anio].[Anio].ALLMEMBERS
*[Dim_Tiempo_].[NombreMesAbreviado].[NombreMesAbreviado].ALLMEMBERS
* [Dim_Tiempo_].[Mes].[Mes].ALLMEMBERS
* [Dim_Tiempo_].[Dim_Tiempo_].[Dim_Tiempo_].ALLMEMBERS
* [Dim_PlantaConsolidada_].[Grupo].[Grupo].ALLMEMBERS
* [Dim_PlantaConsolidada_].[IdGrupo].[IdGrupo].ALLMEMBERS
* [Dim_PlantaConsolidada_].[Unidad].[Unidad].ALLMEMBERS
* [Dim_PlantaConsolidada_].[IdUnidad].[IdUnidad].ALLMEMBERS
* [Dim_PlantaConsolidada_].[sNombrePlantaConsolidada].[sNombrePlantaConsolidada].ALLMEMBERS
* [Dim_PlantaConsolidada_].[keyIdPlantaConsolidada].[keyIdPlantaConsolidada].ALLMEMBERS
* [Dim_ConceptosInventario_].[Dim_ConceptosInventario_].[Dim_ConceptosInventario_]
)}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_VALUE, MEMBER_UNIQUE_NAME ON ROWS
--FROM ( SELECT ( {[Dim_PlantaConsolidada_].[keyIdPlantaConsolidada].[All] } ) ON COLUMNS
FROM ( SELECT ( STRTOSET(#DimPlantaConsolidadaSNombrePlanta, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT ( STRTOSET(#DimPlantaConsolidadaIdUnidad, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT ( STRTOSET(#DimTiempoAnio, CONSTRAINED) ) ON COLUMNS FROM [BSC]
)))
--))) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
As you can see I have column called:
* [Dim_Tiempo_].[Mes].[Mes].ALLMEMBERS
and result come as:
Values 1 to 12, problem is I need to order it ascending like, 1,2,3,4,5,6,7,8,9,10,11,12 but mdx is so complicated, I try to use ORDER filter but I always get error. Is not possible to order by Dimension?

You can put ORDER around all the rows set:
...
NON EMPTY
ORDER(
[Dim_Tiempo_].[Anio].[Anio].ALLMEMBERS
*[Dim_Tiempo_].[NombreMesAbreviado].[NombreMesAbreviado].ALLMEMBERS
*[Dim_Tiempo_].[Mes].[Mes].ALLMEMBERS
*[Dim_Tiempo_].[Dim_Tiempo_].[Dim_Tiempo_].ALLMEMBERS
*[Dim_PlantaConsolidada_].[Grupo].[Grupo].ALLMEMBERS
*[Dim_PlantaConsolidada_].[IdGrupo].[IdGrupo].ALLMEMBERS
*[Dim_PlantaConsolidada_].[Unidad].[Unidad].ALLMEMBERS
*[Dim_PlantaConsolidada_].[IdUnidad].[IdUnidad].ALLMEMBERS
*[Dim_PlantaConsolidada_].[sNombrePlantaConsolidada].[sNombrePlantaConsolidada].ALLMEMBERS
*[Dim_PlantaConsolidada_].[keyIdPlantaConsolidada].[keyIdPlantaConsolidada].ALLMEMBERS
*[Dim_ConceptosInventario_].[Dim_ConceptosInventario_].[Dim_ConceptosInventario_]
,[Dim_Tiempo_].[Mes].CURRENTMEMBER.MEMBER_CAPTION //<<OR [Dim_Tiempo_].[Mes].CURRENTMEMBER.MEMBERVALUE
,BASC
)
ON ROWS
...

Related

How to get previous month data in MDX

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]
);

Hierarchy Level to display from than level down on SSRS Report

So I have a report with 4 parameters;
#LevelParameterCheat; Hierarchy Level, this is the level inside the cube
#DimOrganizationCustomerHierarchy; Organizational Level
#FromDimDateDateSK/#ToDimDateDateSK; used for filtering
Here is the DataSet MDX Query;
SELECT NON EMPTY { [Measures].[Count] } ON COLUMNS, NON EMPTY
{ (DESCENDANTS([Dim Organization].[Customer Hierarchy].Levels(#LevelParameterCheat).ALLMEMBERS) ) }
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME, PARENT_UNIQUE_NAME, LEVEL_NUMBER ON ROWS FROM ( SELECT (
STRTOSET("[Dim Organization].[Customer Hierarchy].&[" + #DimOrganizationCustomerHierarchy + "]", CONSTRAINED) ) ON COLUMNS FROM ( SELECT ( STRTOMEMBER("[Dim Date].[Date SK].&[" + Format(#FromDimDateDateSK,"yyyyMMdd") + "]", CONSTRAINED) :
STRTOMEMBER("[Dim Date].[Date SK].&[" + Format(#ToDimDateDateSK,"yyyyMMdd") + "]", CONSTRAINED) )
ON COLUMNS FROM [Portal Data Mart])) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
What I need: At time of execution the user knows his Org Level and dates to filter. The report needs to display all data from the selected Org Level down.
What I’m looking for; I need to somehow use the Org Level to query the cube and look for the specific level of the selected Org and plug it in the DECENDANTS Function so it displays only from that level on.
What I’ve done; ….ahhhhgggg to many trials and errors . The latest was to try and get the level doing something like this…
WITH MEMBER MEASURES.LevelNumber AS [Dim Organization].[Customer Hierarchy].&[#DimOrganizationCustomerHierarchy].Level.Ordinal
And if that worked I assumed it would bring a numeric value of the level that I then have to concatenate with the DECENDANTS command, something like this…
{ (DESCENDANTS(STRTOSET("[Dim Organization].[Customer Hierarchy].Levels(“level “" + LevelNumber + ").ALLMEMBERS)"))}
Well, something is not right because it doesn’t work. I’m very new to MDX and lacking on the syntax so if someone can point me in the right direction I would appreciate it very much. So far the query above works on the report because I manually enter the Org/Level combination but the user would not know what their Level is. I’ve been at it for almost two weeks and need to fix this. I feel I’m close but not there yet. Please help
well here is the answer to the problem;
`SELECT NON EMPTY { [Measures].[Count] } ON COLUMNS, NON EMPTY
{ (DESCENDANTS(StrToMember( "[Dim Organization].[Customer Hierarchy].&[" + #DimOrganizationCustomerHierarchy + "]",CONSTRAINED).Level.ALLMEMBERS) ) }
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME, PARENT_UNIQUE_NAME, LEVEL_NUMBER ON ROWS FROM ( SELECT (
STRTOSET("[Dim Organization].[Customer Hierarchy].&[" + #DimOrganizationCustomerHierarchy + "]", CONSTRAINED) ) ON COLUMNS FROM ( SELECT (
STRTOMEMBER("[Dim Date].[Date SK].&[" + Format(#FromDimDateDateSK,"yyyyMMdd") + "]", CONSTRAINED) :
STRTOMEMBER("[Dim Date].[Date SK].&[" + Format(#ToDimDateDateSK,"yyyyMMdd") + "]", CONSTRAINED) )
ON COLUMNS FROM [Portal Data Mart])) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS`

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

I got a problem using Multi-Value Parameters in SSRS.
I got a DataSet with this MDX Query :
SELECT NON EMPTY { [Measures].[Air Temperature Out - Fact Germination
Continue] } ON COLUMNS, NON EMPTY { ([81 Germination Continue].[Batch
Number].[Batch Number].ALLMEMBERS * [80 Germination General].[Plant
Name].[Plant Name].ALLMEMBERS * [80 Germination General].[Production
Unit].[Production Unit].ALLMEMBERS * [81 Germination
Continue].[Characteristic Date].[Characteristic Date].ALLMEMBERS * [80
Germination General].[Start Date Unloading].[Start Date
Unloading].ALLMEMBERS * [80 Germination General].[Start Date].[Start
Date].ALLMEMBERS * [80 Germination General].[End Date].[End
Date].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION,
MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT (
STRTOSET(#GerminationGeneralProductionUnit, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT ( STRTOSET(#GerminationGeneralPlantName, CONSTRAINED) )
ON COLUMNS FROM ( SELECT ( STRTOSET(#GerminationContinueBatchNumber,
CONSTRAINED) ) ON COLUMNS FROM [Supervision]))) CELL PROPERTIES VALUE,
BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME,
FONT_SIZE, FONT_FLAGS
When running the report, I got the error :
The restrictions imposed by the CONSTRAINED flag in the STRTOSET
function were violated.
From my research, this means I have to put the full name in the parameters of the DataSet. The thing is that I think I did it, even if it's a bit different from what I saw, because of the construction of the datasets. For example, for the Germinaction Continue Batch Number, my parameter value is :
=Split(Replace(Join(Parameters!BatchNumbers.Value, ","), "[70 Steeping General]", "[81 Germination Continue]"), ",")
As you can guess, my data come from the dimension "[70 Steeping General]", which I try to put in the dimension "[81 Germination Continue]", the values are the same in both dimension ([81 Germination Continue].[Batch Number].[Batch Number] and [70 Steeping General].[Batch Number].[Batch Number]
Does the problem come from the fact that it's a multi-value parameter that looks like this? :
[81 Germination Continue].[Batch Number].[1234567890],
[81 Germination Continue].[Batch Number].[1234567891],
[81 Germination Continue].[Batch Number].[1234567892]
EDIT :
The parameters of the report :
FromSteepingStartDate
ToSteepingStartDate
Both are Date/Time parameters and have an available value set to None, Default Value is DateAdd("m", -1, Today()) and DateAdd("d", -2, Today())
They are used in the DataSet DataSteeping, and the value of the parameter is
="[70 Steeping General].[Start Day].&[" + CStr(Format(CDate(Parameters!FromSteepingGeneralStartDay.Value),
"yyyy-MM-dd"))+ "T00:00:00]"
SteepingGeneralPlantName
This parameter is a multi-value parameter, that initialy come from my dataset DataSteeping, so an autogenerated dataset has been created, with the following query :
WITH MEMBER [Measures].[ParameterCaption] AS [70 Steeping
General].[Plant Name].CURRENTMEMBER.MEMBER_CAPTION MEMBER
[Measures].[ParameterValue] AS [70 Steeping General].[Plant
Name].CURRENTMEMBER.UNIQUENAME MEMBER [Measures].[ParameterLevel] AS
[70 Steeping General].[Plant Name].CURRENTMEMBER.LEVEL.ORDINAL SELECT
{[Measures].[ParameterCaption], [Measures].[ParameterValue],
[Measures].[ParameterLevel]} ON COLUMNS , [70 Steeping
General].[Plant Name].ALLMEMBERS ON ROWS FROM [Supervision]
The dataset is filtered like Parameter.Level <> 0 and Parameter.Caption <> "Unknown"
This parameter is used in every other DataSet, but they don't all come from the same dimension, so the parameter value in the others datasets properties looks like this:
=Split(Replace(Join(Parameters!SteepingGeneralPlantName.Value, ","), "[70 Steeping General]", "[80 Germination General]"), ",")
SteepingGeneralProductionUnit
This parameter is a multi-value parameter too, that initialy come from my dataset DataSteeping, so an autogenerated dataset has been created, but I changed it, so now it doesn't come from my dimension [70 SteepingGeneral], but from [04 Productions Unit], which contains all the productions unit, and is compatible with all the other dimensions, so it was easier to load in the other datasets, the MDX query is :
WITH MEMBER [Measures].[ParameterCaption] AS [04 Production
Units].[Production Unit].CURRENTMEMBER.MEMBER_CAPTION MEMBER
[Measures].[ParameterValue] AS [04 Production Units].[Production
Unit].CURRENTMEMBER.UNIQUENAME MEMBER [Measures].[ParameterLevel] AS
[04 Production Units].[Production Unit].CURRENTMEMBER.LEVEL.ORDINAL
SELECT {[Measures].[ParameterCaption], [Measures].[ParameterValue],
[Measures].[ParameterLevel]} ON COLUMNS , [04 Production
Units].[Production Unit].ALLMEMBERS ON ROWS FROM ( SELECT (
STRTOSET(#PlantsPlant, CONSTRAINED) ) ON COLUMNS FROM [Supervision])
The dataset is filtered like Parameter.Level <> 0
This parameter is used in every other DataSet, only my Dataset DataGermination need an expression for this parameter, because it's from another dimension :
=Split(Replace(Join(Parameters!SteepingGeneralProductionUnit.Value, ","), "[04 Production Units]", "[80 Germination General]"), ",")
TempSteepingLimit
This parameter is not important for the problem, it's just the temperature limit, which I need to display the duration where the temperature is above this limit. It's a text parameter that I convert to a float (with a replace so the user can type "," or "."). It has no dataset and is used in no one, just in a textbox expression.
BatchNumbers
This hidden parameter is populated by a DataSet which return all the batch numbers that match with the other parameters (From/To Steeping Start Date, Plant Name and Production Unit).
They are used in 2 DataSet (DataGermination and DataBatchProcessData), because I couldn't add the Steeping Start Date in those datasets.
In DataGermination, the value for BatchNumber is :
=Split(Replace(Join(Parameters!BatchNumbers.Value, ","), "[70 Steeping General]", "[81 Germination Continue]"), ",")
The dataset that populate this parameter is not autogenerated, I just added it, with this query :
SELECT NON EMPTY { [Measures].[Barley Volume] } ON COLUMNS, NON EMPTY
{ ([70 Steeping General].[Batch Number].[Batch Number].ALLMEMBERS *
[70 Steeping General].[Plant Name].[Plant Name].ALLMEMBERS * [70
Steeping General].[Production Unit].[Production Unit].ALLMEMBERS * [65
Batch Process Data].[Steeping Start Date].[Steeping Start
Date].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION,
MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT (
STRTOMEMBER(#FromSteepingGeneralStartDay, CONSTRAINED) :
STRTOMEMBER(#ToSteepingGeneralStartDay, CONSTRAINED) ) ON COLUMNS FROM
( SELECT ( STRTOSET(#SteepingGeneralProductionUnit, CONSTRAINED) ) ON
COLUMNS FROM ( SELECT ( STRTOSET(#SteepingGeneralPlantName,
CONSTRAINED) ) ON COLUMNS FROM [Supervision]))) CELL PROPERTIES VALUE,
BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME,
FONT_SIZE, FONT_FLAGS
(Sorry for my english)
Don't hesitate to ask questions!
Thank's for your help! :)

Parameterized MDX query in SSRS 2008 with Multiple Rank Columns

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)

Passing MultiValue Parameter in MDX

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 .. )