Percentage Calculation on MDX - ssas

Im new to MDX Query and I'm trying to add a percentage on attended percentage in each row. The following code :
SELECT {[Measures].[Client Interventions Count]* [Dim Intervention Attendance].[Attended].Children} ON COLUMNS,
[Dim Date].[Calendar].[Month Name] ON ROWS
FROM [Client Intervention]
procude a result of :
How can I perform a calculation on each row? For example, first row November 2007 , total client intervention count = 68 , so the percentage count should be 57/68 %
Any idea?? Thanks

Use a calculated member - you can find several examples here. The idea for the query is as following:
WITH MEMBER [Dim Intervention Attendance].[Attended].[%] AS
( [Dim Intervention Attendance].[Attended].[Attented],
[Measures].[Client Interventions Count] )
/ ( [Dim Intervention Attendance].[Attended].[Not Attented],
[Measures].[Client Interventions Count] )
SELECT
[Measures].[Client Interventions Count]
* { [Dim Intervention Attendance].[Attended].[%],
[Dim Intervention Attendance].[Attended].Children } ON COLUMNS,
[Dim Date].[Calendar].[Month Name] ON ROWS
FROM [Client Intervention
]

Related

Calculating Cumulative Values MDX

I was trying to calculate cumulative values for the measure Closed WIT History
for the Month level, but had no luck
This is the Time dimension I have:
And this is my query:
WITH MEMBER [MEASURES].[Sales To Date]
AS
Sum
(
PeriodsToDate([DWH Dim Date].[(All)]),[Measures].[Closed WIT History]
)
SELECT
{[Measures].[Closed WIT History], [MEASURES].[Sales To Date]} ON COLUMNS,
[DWH Dim Date].[Month Name].[Month Name].Members ON ROWS
FROM [CUBE_Rel_1_AED_SAFe]
where [DWH Dim Date].[Year].&[2018]
But, for some reason, I get these results:
What am I doing wrong? I've also tried this Query:
WITH
MEMBER [MEASURES].[Sales To Date] as
SUM(
{[DWH Dim Date].CurrentMember.Level.Members}.Item(0):[DWH Dim Date].CurrentMember,[Measures].[Closed WIT History]
)
SELECT
{[Measures].[Closed WIT History],[Measures].[Sales To Date]} ON COLUMNS,
[DWH Dim Date].[Month Name].[Month Name].Members ON ROWS
FROM [CUBE_Rel_1_AED_SAFe]
where [DWH Dim Date].[Year].&[2018]
But then I get error like so:
You could click on #Error to see the detailed information. In addition, you also could use expression like below to achieve your goal
with member[Measures].[S2] AS
sum(
{[Date].[Month Name].&[2005]&[January]:[Date].[Month Name].CurrentMember}
, [Measures].[Internet Sales Count])
select nonempty ([Date].[Month Name].[Month Name].members) on rows, nonempty ({[Measures].[S2],[Measures].[Internet Sales Count]}) on columns from [Analysis Services Tutorial]
Zoe

Query to only display matching elements in two dimensions

Short question:
Any idea how I can pull the name from one dimension entry and apply it to another as filter?
Long description: My cube has has dimensions for manufacturer and seller, and I only need sales for "themselves". The dimensions are loaded from distinct tables in the source but have entries with the exact same name.
Manufacturer Seller
A A *
A D
B B *
C C *
C A
C D
A, B and C sell their products themselves, A and C also sell through reseller D. C also sells through A. I'd like to filter for the marked rows only (names matching).
In SQL this would be simple, or the cube might be easily enhanced to flag "own sales", but both options are not available. I need to query the cube "as is".
I tried using STRTOMEMBER and CURRENTMEMBER like so (with NAME and MEMBER_NAME):
STRTOMEMBER("[Dim Seller].[Seller].[" + [Dim Producer].[Producer].CURRENTMEMBER.NAME + "]
That actually works, syntactically, but CURRENTMEMBER seems to always evaluate to ALL and delivers the (correct) measure value for the ALL element yet not the one for matching name.
I also tried to create a WHERE setting the two names equal
[Dim Seller].[Seller].CURRENTMEMBER.NAME = [Dim Producer].[Producer].CURRENTMEMBER.NAME
but that is very SQL and not valid in MDX.
The whole query looks like this:
SELECT
NON EMPTY {
[Measures].[Value]
} ON COLUMNS
, NON EMPTY { (
{
[Dim Producer].[Producer].[A]
, [Dim Producer].[Producer].[B]
, [Dim Producer].[Producer].[C]
}
* [Dim Seller].[Seller].[Seller].ALLMEMBERS
// This line needs to be trimmed to same name as producer
) } ON ROWS
FROM
[Cube]
The producer list is coming from a config file and string-concatenated to the query and subject to change. Having a second seller list to be kept in sync would be a burden but also (when C sells through A) deliver wrong results.
Any idea how I can pull the name from one dimension entry and apply it to another?
The HAVING clause might help you:
SELECT
NON EMPTY {
[Measures].[Value]
} ON COLUMNS
, NON EMPTY {
{
[Dim Producer].[Producer].[A]
, [Dim Producer].[Producer].[B]
, [Dim Producer].[Producer].[C]
}
* [Dim Seller].[Seller].[Seller].ALLMEMBERS
}
HAVING
[Dim Seller].[Seller].CURRENTMEMBER.MEMBER_NAME =
[Dim Producer].[Producer].CURRENTMEMBER.MEMBER_NAME
ON ROWS
FROM
[Cube]
Use the GENERATE function to do the job for you.
with set Producers as
{[Dim Producer].[Producer].[A]
,[Dim Producer].[Producer].[B]
,[Dim Producer].[Producer].[C]}
set Sellers as
[Dim Seller].[Seller].members
//For every producer, get the seller who shares the same name.
set ProducersHavingSameNameAsSellers as
GENERATE(Producers, GENERATE(Sellers, filter
(Sellers,
[Dim Seller].[Seller].CURRENTMEMBER.MEMBER_NAME =
[Dim Producer].[Producer].CURRENTMEMBER.MEMBER_NAME
)
)
)
SELECT
NON EMPTY [Measures].[Value] ON COLUMNS,
ProducersHavingSameNameAsSellers ON ROWS
FROM [Cube]

How to combine measures with different dimensionality into single select statement using MDX & Analysis Services (SSAS)?

I would like to add a measure that has different dimensionality to the same SELECT mdx statement. In general, most of my measures are linked to [Customer Creation Date].[Date Hierarchy].[Month Name].
However, Anonymous customers do not have the link to customer creation date; therefore, I have to link anonymous to Enquiry Creation Date. How to combine two measures into single select query.
> WITH MEMBER [Measures].[Allow Contact] as
([Measures].[# CRM Customers],[Customer].[Customer Allow Contact].&[Yes],[Customer].[Customer Status].&[Active] )
MEMBER [Measures].[Total Identified Customers] AS
([Measures].[# CRM Customers],[Customer].[Customer Status].&[Active] )
MEMBER [Measures].[Anonymous Customers] AS
([Measures].[# Unique Distinct Customers on Contact],[Enquiry].[Anonymous].&[Yes])
SELECT NON EMPTY { Measures].[Allow Contact],
[Measures].[Total Identified Customers]
//,[Measures].[Anonymous Customers]
} ON COLUMNS
,NON EMPTY ([Customer Creation Date].[Date Hierarchy].[Month Name]
//,[Enquiry Creation Date].[Date Hierarchy].[Month Name] //How to add different dimensionality
) ON ROWS
FROM [Cube]
If both time dimensions have the same structure (which should obviously be the case if they are implemented as role playing dimensions on the same dimension object), you can use the LinkMember function in the definition of [Measures].[Anonymous Customers] to use the [Customer Creation Date].[Date Hierarchy] in the rows, but use these dates as the [Enquiry Creation Date].[Date Hierarchy] in the measure calculation:
WITH MEMBER [Measures].[Allow Contact] as
([Measures].[# CRM Customers],[Customer].[Customer Allow Contact].&[Yes],[Customer].[Customer Status].&[Active] )
MEMBER [Measures].[Total Identified Customers] AS
([Measures].[# CRM Customers],[Customer].[Customer Status].&[Active] )
MEMBER [Measures].[Anonymous Customers] AS
([Measures].[# Unique Distinct Customers on Contact],[Enquiry].[Anonymous].&[Yes],
LinkMember([Customer Creation Date].[Date Hierarchy].CurrentMember, [Enquiry Creation Date].[Date Hierarchy])
SELECT NON EMPTY { Measures].[Allow Contact],
[Measures].[Total Identified Customers]
,[Measures].[Anonymous Customers]
} ON COLUMNS
,NON EMPTY ([Customer Creation Date].[Date Hierarchy].[Month Name]
) ON ROWS
FROM [Cube]

MDX crossjoin with 5 dimensions

Assuming we have the following dimension
DATE
CONTRACTOR
COLOR
SIZE
and a set of 6 measures, we want to get the 6 measures for every Semestrer, Trimester, Month, Contractor, Color and Size for a given Year.
Here is my MDX query:
SELECT
{
... the 6 measures ...
} ON COLUMNS,
{
(
[Dim DATE].[year].[year].AllMembers *
[Dim DATE].[SEMESTRE NOM].[SEMESTRE NOM].AllMembers *
[Dim DATE].[TRIMESTRE NOM].[TRIMESTRE NOM].AllMembers *
[Dim DATE].[MOIS NOM].[MOIS NOM].AllMembers *
[Dim CONTRACTOR].[Name CONTRACTOR].AllMembers *
[Dim COLOR].[Name COLOR].AllMembers *
[Dim SIZE].[Name SIZE].AllMembers
)
} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM (
SELECT ( { StrToSet( "[Dim DATE].[year].[year].&[" + #Year + "]" , CONSTRAINED ) }
) ON COLUMNS
FROM [TheCube]
This is very slow (more than 20 minutes), with only 6 Contractors, 6 Color, 18 sizes... and what is the differences between .AllMembers and .Members ?
Depending on the actual number of years in your hierarchy, you might create a quite large set with the crossjoin. As icCube mentionned in the comment, why not using :
StrToSet( "[Dim DATE].[year].[year].&[" + #Year + "]" , CONSTRAINED )
in the crossjoin on the ROWS ?
AllMembers vs Members; here is a doc; allmembers include the calc. members; do you have any costly calc. members ?
How many members do you have in [Dim DATE].[MOIS NOM].[MOIS NOM].AllMembers ? trimestre, semestre ?

Merging two tuples in the same hierarchy into one (in MDX WITH SET command)

The following MDX query returns measure X on 3 tuples: 2001, 2002-1 and 2002-2. What I am trying to do is merging 2002-1 and 2002-2 into one tuple and have the measure X for 2001 and 2002-1&2. Using SUM function is not possible. Because measure X is used on other axis.
with
member v as [Measures].[X]
set w as {[Dim Date].[Calendar Date].[Year].&[2001],
[Dim Date].[Calendar Date].[Month].&[1]&[2002],
[Dim Date].[Calendar Date].[Month].&[2]&[2002]}
select w on 0, v on 1
from [DS];
You can add calculated members in [Dim Date]:
with
member [Dim Date].[Calendar Date].[2002 All] as [Dim Date].[Calendar Date].[Month].&[1]&[2002] + [Dim Date].[Calendar Date].[Month].&[2]&[2002]
...
You can use aggregate or sum functions if your prefer this syntax.