MDX Filtering dimension members with result of other dimension - ssas

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;

Related

MDX-Query - Query with to many rows. Set correct filter

I work on a problem with an MDX Query.
The cube contains models and serials (units) and should show all units in warranty for each year.
This is the a cube with this Dimensions/Measures:
CubeOverview
Now I would select all Serials which are in warranty for a special year.
The problem is that the whole Table v Dim Unit Model 4IB Test contains more than 50 Mio rows which results alsways to an QueryTimeout or sometimes to an MemoryException.
At the moment I have a MDX query (see below) which works if I select special model. But I need the filter to all models.
WITH
MEMBER [Measures].[QtyTotal] AS
[Measures].[QtyInWarranty] + [Measures].[QtyInExtension]
SELECT
NON EMPTY
{
[Measures].[QtyStdOut] ,[Measures].[QtyInExtension] ,[Measures].[QtyStdIn]
,[Measures].[QtyInWarranty] ,[Measures].[QtyTotal] ,[Measures].[SumStartWarranty]
} ON COLUMNS
,NON EMPTY
{
crossjoin(
[v Dim Unit Model 4IB Test].[ModelUnitMapping].[Id Unit].Members
,[Dim Country].[Id Country].[Id Country].members
,[Dim Calendar].[Calendar].[Month Name4report].members
)
} ON ROWS
FROM
(
SELECT
{
[v Dim Unit Model 4IB Test].[model no short].[Model No Short].&[SampleModel]
} ON COLUMNS
FROM
(
SELECT
{
[Dim Calendar].[Calendar].[Year].&[2015]
} ON COLUMNS
FROM [InstalledBaseCS_Serial]
)
)
Does anybody knows a tip to update the query to get all units for one year (round about 4 Mio rows)?
If you're trying to return the results to a visible grid in MDXstudio or SSMS then it may be timing out because there is quite a bit to render.
If you use OPENQUERY or the CLR OLAP Extensions then try the following:
Do not return the results to the screen but INSERT results into a table.
Simplifiy your script by taking away the custom measure. This can easily be calculated later as it is trivial: I have a feeling it is slowing down ssas.
Script
SELECT
NON EMPTY
{
[Measures].[QtyStdOut]
,[Measures].[QtyInExtension]
,[Measures].[QtyStdIn]
,[Measures].[QtyInWarranty]
,[Measures].[SumStartWarranty]
} ON 0
,NON EMPTY
[v Dim Unit Model 4IB Test].[ModelUnitMapping].[Id Unit].Members
*[Dim Country].[Id Country].[Id Country].members
*[Dim Calendar].[Calendar].[Month Name4report].members
ON 1
FROM
(
SELECT
[v Dim Unit Model 4IB Test].[model no short].[Model No Short].&[SampleModel] ON 0
FROM
(
SELECT [Dim Calendar].[Calendar].[Year].&[2015] ON 0
FROM [InstalledBaseCS_Serial]
)
);

MDX,how to flatten the result of Descendants function

I have a hierarchy with 5 level,I use Descendants() to retrieve all lower level of a member.But i end up with a one column result where i like to have a result with one column for each level.So on each row i repeat the parent,grand parents etc of the current member.
WITH
MEMBER [Measures].[key] AS
[DimGLAcct].[MgtCOA].CurrentMember.UNIQUENAME
MEMBER [Measures].[level_] AS
[DimGLAcct].[MgtCOA].CurrentMember.level.ordinal
SELECT
{
[Measures].[key]
, [Measures].[level_]
, [Measures].[Actuals]
} ON COLUMNS,
{
Descendants(
[DimGLAcct].[MgtCOA].[Mparent5].&[MCOA].&[400000M - Total operating overhead expenses].&[440000M - Other expenses].&[441000M - Other expenses]
,
,SELF_AND_AFTER
)
} ON ROWS
FROM [Model];
I cannot quite suss out the names of your levels but it is ok to do the following in mdx:
WITH
MEMBER [Measures].[key] AS
[DimGLAcct].[MgtCOA].CurrentMember.UNIQUENAME
MEMBER [Measures].[level_] AS
[DimGLAcct].[MgtCOA].CurrentMember.level.ordinal
SELECT
{
[Measures].[key]
, [Measures].[level_]
, [Measures].[Actuals]
} ON COLUMNS,
[DimGLAcct].[LevelX]
*[DimGLAcct].[LevelY]
*[DimGLAcct].[LevelZ]
*[DimGLAcct].[LevelK]
ON ROWS
FROM [Model];
Each of the levels in your user hierarchy will have respective attribute hieraries - which are used in the above.

SSAS: How can I create calculated member using multiple conditions on different hierarchy

I have problem with my SSAS Cube.
I have to implement basic calculation to my Cube:
sum(Ammount) where BOOK = "Assets" and CD_PRODUCT_L4 <> "LoanLoss"
My dimmension is in image below:
Dimension attributes: BOOK, CD_PRODUCT_L4, CD_PRODUCT_L5, ..
Hierarchy PROD: CD_PRODUCT_L4 - CD_PRODUCT_L5
CREATE MEMBER CURRENTCUBE.[Measures].[Principal Loans]
AS (
except(
[PLV PRH HDIM CB].[BOOK].&[ASSETS_ON],
[PLV PRH HDIM CB].[COD PRODUCT L4].&[51L4]
),
[Measures].[EOM PRINCIPAL_a])
The biggest thing is that conditions are not from same hierarchy level so I can't use except and I know no other way to implement this particular condition set
Please HELP, Thank you
Product dimmension model
I manage to solve the issue by adding hierarchy to my dimension which allowed me to use except as I wanted before but I'am not satisfied with this solution because it looks more like workaround then solution
CREATE MEMBER CURRENTCUBE.[Measures].[Principal Loans] AS
sum((except([PLV PRH HDIM CB].[Hierarchy BOOK].[BOOK].&[ASSETS_ON].children,[PLV PRH HDIM CB].[Hierarchy BOOK].[COD PRODUCT L4].&[51L4]),[Measures].[EOM PRINCIPAL_a]))
This is probably the closest example that I can provide you to what you need.
This, code below, is just one of about 50 or so Measures we have defined, ranging from Counts, Averages, Sums, Percentages, etc. We take a single DW value and perform at least 2 seperation calculations, most have 4 or more different calculations, from that one field.
CREATE MEMBER CURRENTCUBE.[Measures].[Count Previous Difference]
AS Case
// Test for current coordinate being on (All) member.
When [Date].[YearMonth].CurrentMember.Level Is [Date].[YearMonth].[(All)]
Then "NA"
Else
( [Date].[YearMonth].CurrentMember, [Measures].[Gross Count] )
-
( ParallelPeriod (
[Date].[YearMonth].CurrentMember.Level,
1,
[Date].[YearMonth].CurrentMember
),
[Measures].[Gross Count]
)
End,
FORMAT_STRING = "#,##0.00;-#,##0.00",
NON_EMPTY_BEHAVIOR = { [Gross Count] },
VISIBLE = 0 , ASSOCIATED_MEASURE_GROUP = 'Some Summary';
Keep in mind we also use our DW & Cube with SharePoint and SSRS reports.

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)

Values of dimension with like clause 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]