Values of dimension with like clause SSAS - ssas

i want values of dimension with like clause.. i tried this
WITH
SET CITY
AS
FILTER(
[CITY].[CITY].CHILDREN,
vbamdx!INSTR([CITY].[CITY].CURRENTMEMBER.Name,'In',1 >= 1 )
)
MEMBER [Measures].[Label] AS [CITY].[CITY].CURRENTMEMBER.MEMBER_CAPTION
SELECT {[Measures].[Label]
} ON COLUMNS ,
[CITY].[CITY].ALLMEMBERS ON ROWS
FROM [TEST_Cube]
want All Cities with name containing "In".

You're not using the filtered set you made.
Also, you're naming your set the same as the dimension which might give you trouble.
Try:
WITH
SET FilteredCities AS
FILTER
(
[CITY].[CITY].CHILDREN,
vbamdx!INSTR([CITY].[CITY].CURRENTMEMBER.Name,'In',1 >= 1 )
)
MEMBER [Measures].[Label] AS
[CITY].[CITY].CURRENTMEMBER.MEMBER_CAPTION
SELECT
{
[Measures].[Label]
}
ON COLUMNS ,
FilteredCities //Use the set
ON ROWS
FROM [TEST_Cube]

Related

MDX query - Subselect implementation - Select all values of a column except one

I have to implement a query with the following requirements.
1) I need to have multiple conditions(with AND,OR).
2) There are conditions where I need to exclude the records with a particular value.
SELECT {...} ON Columns, {...} ON ROWS
FROM
(SELECT {([Element1].[Value].&[98]&[002], [Element2].Value.&[Value1]),
([Element1].[Value].&[98]&[004], [Element2].Value.&[Value2]), ([Element1].[Value].&[98]&[005], [Element2].Value.NOTIN[value1, value2]), } ON Columns
FROM [CubeName])
I have mentioned NOTIN[value1,value2]) as I am unaware of how this can be implemented. I have to get all values except those mentioned. Please let me know if any one can provide a solution.
You would generally use the function EXCEPT to exclude some members from a set:
SELECT
{...} ON 0
, {...} ON 1
FROM
(
SELECT
EXCEPT(
[Element1].[Value].[Value].MEMBERS //<<name of the full set
,{ //<<the set to be excluded
[Element1].[Value].&[98]&[002],
[Element1].[Value].&[98]&[004],
[Element1].[Value].&[98]&[005]
} ON 0
FROM [CubeName]
);
The above could be expanded out to tuples but the first argument will need to be a cross-join:
SELECT
{...} ON 0
, {...} ON 1
FROM
(
SELECT
EXCEPT(
[Element1].[Hier1].[Hier1].MEMBERS
* [Element1].[Hier2].[Hier2].MEMBERS //<<name of the full set
,{ //<<the set to be excluded
([Element1].[Hier1].[Hier1].&[Value1],[Element1].[Hier2].[Hier2].&[Value1]),
([Element1].[Hier1].[Hier1].&[Value2],[Element1].[Hier2].[Hier2].&[Value2]),
([Element1].[Hier1].[Hier1].&[Value3],[Element1].[Hier2].[Hier2].&[Value3]),
} ON 0
FROM [CubeName]
);

MDX query optimization while using CrossJoin

I am writing an MDX query in which i am selecting some Measures and while selection i have a where condition in which i am doing a cross join two facts , one is date and another a unique id and i am passing around 2000 unique ids and the query is taking around 20 minutes to execute and give the result.
Please find below query for the same
SELECT {[Measures].[TOTAL1], [Measures].[TOTAL2], [Measures].[TOAL3]} ON COLUMNS,
" + " {TOPCOUNT(FILTER([ID].[Ids].MEMBERS,
[ID].CurrentMember > 0),
5,[Measures].[TOTAL])} " + "ON ROWS
FROM [CHARTS]
WHERE({[Date].&[2015-09-01 00:00:00.0]}*{[NUM].[1],[NUM].[10],"
+ "[NUM].[18],[NUM].[47],[NUM].[52],[NUM].[105],[NUM].[126],[NUM].[392],"
+ "[NUM].[588],[NUM].[656],[NUM].[995],[NUM].[1005],[NUM].[1010],[NUM].[1061]})";
The straight mdx without the string manipulation operators (+) is as follows:
SELECT
{
[Measures].[TOTAL1]
,[Measures].[TOTAL2]
,[Measures].[TOAL3]
} ON COLUMNS
,{
TopCount
(
Filter
(
[ID].[Ids].MEMBERS
,
[ID].CurrentMember > 0
)
,5
,[Measures].[TOTAL]
)
} ON ROWS
FROM [CHARTS]
WHERE
{[Date].&[2015-09-01 00:00:00.0]}
*
{
[NUM].[1]
,[NUM].[10]
,[NUM].[18]
,[NUM].[47]
,[NUM].[52]
,[NUM].[105]
,[NUM].[126]
,[NUM].[392]
,[NUM].[588]
,[NUM].[656]
,[NUM].[995]
,[NUM].[1005]
,[NUM].[1010]
,[NUM].[1061]
};
Can you please tell me the different performance optimization techniques for the same.
TopCount is slow if you use the third ordering parameter - it is better to order the data first and then feed your pre-ordered set into TopCount with just 2 parameters:
WITH
SET [S0] AS
Filter
(
[ID].[Ids].MEMBERS
,
[ID].CurrentMember > 0
)
SET [S1] AS
Order
(
[S0]
,[Measures].[TOTAL]
,BDESC
)
SET [S2] AS
TopCount
(
[S1]
,5
)
SELECT
{
[Measures].[TOTAL1]
,[Measures].[TOTAL2]
,[Measures].[TOAL3]
} ON COLUMNS
,[S2] ON ROWS
FROM [CHARTS]
WHERE
{[Date].&[2015-09-01 00:00:00.0]}
*
{
[NUM].[1]
,[NUM].[10]
,[NUM].[18]
,[NUM].[47]
,[NUM].[52]
,[NUM].[105]
,[NUM].[126]
,[NUM].[392]
,[NUM].[588]
,[NUM].[656]
,[NUM].[995]
,[NUM].[1005]
,[NUM].[1010]
,[NUM].[1061]
};

How to extract month-year from date from MDX Query

I need to filter data from Cube using Date without day inclusion.
Currently I am using following MDX query, that is fetching measures data starting from 1st day of the year and ending on the last day.
But, I only want to have Month-Year in date time at rows rather than DateTime with all days. ( Here my field for date is : [Period].[TransportDate] )
Following is the MDX Query.
SELECT
NON EMPTY
{
[Measures].[ConsignmentCount]
, [Measures].[CBM]
, [Measures].[LDM]
, [Measures].[Weight]
, [Measures].[Amount] } ON COLUMNS,
NON EMPTY
{ [Period].[TransportDate].Children } ON ROWS
FROM
(
SELECT
(
{ [Period].[YearAndMonth].[ConsignmentYear].&[2014]
, [Period].[YearAndMonth].[ConsignmentYear].&[2015] }
) ON COLUMNS
FROM [RebellOlap]
)
Above query fetching all records starting from 1st day till the last day of 2015. See attached image ( allRecords )
But I want somehow in following manner ( Required Data Set )
I want single column instead of Month and year. So
final data set should be
( e.g Date ( 07-2015 ), Amount,CBM, LDM, Num,. Consignments )
I know there's a way to extract only month and year from the whole date. But that works only for single date. What I want to have all dates must be filtered with the inclusion of month and Year and data should also corresponds to those dates accordingly. See above expected filtered data set.
Edit
WITH MEMBER [YearMo] AS
[Period].[ConsignmentYear].Currentmember.Name
+ "-" +
[Period].[ConsignmentMonth].Currentmember.Name
SELECT
NON EMPTY
{
[Measures].[ConsignmentCount]
, [Measures].[CBM]
, [Measures].[LDM]
, [Measures].[Weight]
, [Measures].[Amount]
} ON COLUMNS ,
NON EMPTY
(
{
[Period].[YearAndMonth].[ConsignmentMonth]
}
) ON ROWS
FROM
(
SELECT
(
{
[Period].[YearAndMonth].[ConsignmentYear].&[2014]
, [Period].[YearAndMonth].[ConsignmentYear].&[2015]
}
) ON COLUMNS
FROM [RebellOlap]
)
above produces result but without Year.
I want somehow to have year with month on the same columns.
so 01 would becomd 01-2014.
Could you help me
Results without concatenation
Either you have to create a new field as 'YYYY-mm' in the dimension view (cube design-sql view) or you can concatenate the year & month dimension attributes (Example below).
Example Code:
WITH MEMBER [YearMo] AS
[Period].[Monthly].Currentmember.Name
+ "-" + [Period].[YearAndMonth].Currentmember.Name
SELECT
NON EMPTY {[Measures].[ConsignmentCount], [Measures].[CBM], [Measures].[LDM], [Measures].[Weight], [Measures].[Amount]} ON COLUMNS
, NON EMPTY ( { [Period].[Monthly].[Year] } , { [Period].[YearAndMonth].[ConsignmentMonth] } ) ON ROWS
FROM
(
SELECT ( { [Period].[YearAndMonth].[ConsignmentYear].&[2014], [Period].[YearAndMonth].[ConsignmentYear].&[2015] } ) ON COLUMNS
FROM [RebellOlap]
)
Maybe try hosting the calculated member in a different hierarchy. I have guessed this [Forwarder].[Forwarder].[All] and you will need to adjust to a hierarchy that exists in your cube:
WITH MEMBER [Forwarder].[Forwarder].[All].[YearMo] AS
[Period].[Year].Currentmember.Name
+ "-" +
[Period].[Month].Currentmember.Name
SELECT
NON EMPTY
{
[Measures].[ConsignmentCount]
, [Measures].[CBM]
, [Measures].[LDM]
, [Measures].[Weight]
, [Measures].[Amount]
} ON COLUMNS ,
NON EMPTY
[Period].[Year].[Year]
*[Period].[Month].[Month]
*[Forwarder].[Forwarder].[All].[YearMo]
ON ROWS
FROM
(
SELECT
(
{
[Period].[YearAndMonth].[ConsignmentYear].&[2014]
, [Period].[YearAndMonth].[ConsignmentYear].&[2015]
}
) ON COLUMNS
FROM [RebellOlap]
)
Or if the above produces an error then you may need to create a measure first:
WITH
MEMBER [Measures].[YearMoString] AS
[Period].[Year].Currentmember.Name
+ "-" +
[Period].[Month].Currentmember.Name
MEMBER [Forwarder].[Forwarder].[All].[YearMo] AS
(
[Forwarder].[Forwarder].[All]
,[Measures].[YearMoString]
)
SELECT
NON EMPTY
{
[Measures].[ConsignmentCount]
, [Measures].[CBM]
, [Measures].[LDM]
, [Measures].[Weight]
, [Measures].[Amount]
} ON COLUMNS ,
NON EMPTY
[Period].[Year].[Year]
*[Period].[Month].[Month]
*[Forwarder].[Forwarder].[All].[YearMo]
ON ROWS
FROM
(
SELECT
(
{
[Period].[YearAndMonth].[ConsignmentYear].&[2014]
, [Period].[YearAndMonth].[ConsignmentYear].&[2015]
}
) ON COLUMNS
FROM [RebellOlap]
)

MDX Filtering dimension members with result of other dimension

I would like to filter a dimension for cube security with some information that are in another dimension.
So - I have a dimension which holds some account Responsible (Account Number and the initials on the one responsible) and another Dimension with all accounts.
I would like to make sure, that a person only can see movements on the accounts on which they are responsible.
I can make the filtering work like this:
SELECT
{} ON 0
,{
Exists
(
Filter
(
[Accounts].[Accounts].[AccountNo]
*
[AccountResponsible].[AccountResponsible].[AccountNo]
,
[Accounts].[Accounts].Properties("key")
=
[AccountResponsible].[AccountResponsible].Properties("key")
)
,[AccountResponsible].[Responsible].&[MSA]
)
} ON 1
FROM mycube;
the problem is, that there are two columns, and I can't use that in cube security. Is there a way to rewrite this, so that I actually get only one column with the members that the user are allowed to see?
Try using the Extract function:
SELECT
{} ON 0
,
EXTRACT(
{
Exists
(
Filter
(
[Accounts].[Accounts].[AccountNo]
*
[AccountResponsible].[AccountResponsible].[AccountNo]
,
[Accounts].[Accounts].Properties("key")
=
[AccountResponsible].[AccountResponsible].Properties("key")
)
,[AccountResponsible].[Responsible].&[MSA]
)
}
,[Accounts].[Accounts] //<<HIERARCHY YOU WISH TO EXTRACT
) ON 1
FROM mycube;

MDX query - best salesmen who sold all of given products

Let's say I have two simple dimensions:
Products - with id and name
Salesmen - with id and name
My fact table is named SALES and contains the ids of the abovementioned.
I need to produce a query that will show the names of salesmen who sold all of the given products.
This code solves the problem for two items X and Y:
SELECT
{} on 0,
EXISTS(
EXISTS(
{[Salesmen].[Name].MEMBERS},
{[Products].[Name].&[X]}
)
,{[Products].[Name].&[Y]}
)
ON 1
FROM [Test];
The other version is:
SELECT
{} on 0,
INTERSECT(
NONEMPTY(
{[Salesmen].[Name].MEMBERS}
,([Products].[Name].&[X])
)
,NONEMPTY(
{[Salesmen].[Name].MEMBERS}
,([Products].[Name].&[Y])
)
)
ON 1
FROM [Test];
However, this method becomes troublesome if the list of given products is large, for example - 100 random products..
Do you have a property member_key for the hierarchy [Products].[Name] ? We can test like this:
WITH
MEMBER [Measures].[Meas1] AS
[Products].[Name].CurrentMember.PROPERTIES("KEY ID")
MEMBER [Measures].[Meas2] AS
[Products].[Name].CurrentMember.MEMBER_Key
MEMBER [Measures].[Meas3] AS
[Products].[Name].CurrentMember.MEMBERvalue
select
{
[Measures].[Meas1]
,[Measures].[Meas2]
,[Measures].[Meas3]
} on COLUMNS,
[Products].[Name].MEMBERS on ROWS
FROM [Test];
Hopefully one of the custom measures gives you a value? I'll assume Meas2 is working (swap to a different one if Meas1 or Meas3 is returning numbers)
WITH
MEMBER [Measures].[Meas2] AS
[Products].[Name].CurrentMember.MEMBER_Key
SET [ProdsetA] AS
FILTER(
[Products].[Name].MEMBERS
,[Measures].[Meas2] <100
)
SET [ProdsetB] AS
FILTER(
[Products].[Name].MEMBERS
,[Measures].[Meas2] >500
)
SELECT
{} on 0,
INTERSECT(
NONEMPTY(
{[Salesmen].[Name].MEMBERS}
,[ProdsetA]
)
,NONEMPTY(
{[Salesmen].[Name].MEMBERS}
,[ProdsetB]
)
)
ON 1
FROM [Test];
... the >100 and <500 are important. These are the criteria for the filter function to use. The custom set [ProdsetA] will only contain Products that have MEMBER_Key that are <100 whereas the custom set [ProdsetB] will only contain Products that have MEMBER_Key that are >500. You need to use the member values presented to you by the first script to decide what values 100 and 500 should be in your cube context (...I don't know the key values in your cube so just used 100 and 500 as placeholders)