MDX Query - Differece between two columns - mdx

It is possible to calculate a measure which is the difference between two members of the same dimension?
What I want to do is something like this:
([Year]. ["Year X"], [Measures]. [All]) - ([Year]. ["Year X - 1"], [Measures]. [All])
Thanks in advance

A measure using lag can be created:
([Year].CURRENTMEMBER, [Measures].[All]) - ([Year].CURRENTMEMBER.LAG(1), [Measures].[All])
....but what is [Measures].[All] ?! Cubes don't have an All member in the Measures dimension.

Related

Simple MDX Calculated Member

In my simple cube, I have a measure = \[Measure\].\[Salary\], I have also \[DimEmpployee\].\[EmployeeLastName\].\[Smith\]. I would like to create calculated measure, where I can display in Axis 0 two measures - \[Measure\].\[Salary\] and calculated measure \[Measure\].\[SmithsSalaries\], to compare difference between Smith's earnings vs Total Salary.
I would like to compare Measure.SmithSalaries with other measures accross all diemensions. Is it possible to create such a measure using SCOPE statement?
I was playing around SCOPE statements, but it was displaying results only if DimEmployee was selected. I am looking for something which is running in blocks to avoid performance issues.
I think you only need a simple calculated measure.
CREATE MEMBER CURRENTCUBE.[Measures].[SmithSalaries]
AS ([DimEmployee].[EmployeeLastName].[Smith], [Measures].[Salary]),
VISIBLE = 1 ;
After that you can combine that with you total salary for example to get a ratio.
CREATE MEMBER CURRENTCUBE.[Measures].[SmithSalaries Ratio]
AS DIVIDE(([DimEmployee].[EmployeeLastName].[Smith], [Measures].[Salary]),[Measures].[Salary])
VISIBLE = 1 ;
SCOPE allows you to have different behaviors when different combinations of Dimensions are into play, like returning a different calculation when the DimEmployee is selected but otherwise just return the normal calculation. Like a Very efficient IF condition to check what are in the Axis of this calculation.

SSAS Calc measure on filtering multi-members

I am trying to create a formula in Calculated measure but none is working correctly
Dimension Cell has multiple members including Control and Core. I also have measure called [Measures].[Rate] which is precalculated as percentage
I need to achieve below formula
(([Measures].[Rate] in [Cell].[ABC].&[Control] and [Cell].[ABC].&[Core])
- ([Measures].[Rate] not in [Cell].[ABC].&[Control] and [Cell].[ABC].&[Core]))
/ ([Measures].[Rate] in [Cell].[ABC].&[Control] and [Cell].[ABC].&[Core])
Something like (A+B)/A but I am not able to calculate individual A and B.
Please note [Measures].[Rate] is in percentage format so cannot be summed up
EDIT
Also any idea if the same above has to be done with two slices from different dimension for single measure
eg.
([Measures].[Rate] in [Cell].[ABC].&[Control] and [Cell].[ABC].&[Core] also in [Data].[PQR].&[Yes])
or
SUM (
{ [Cell].[ABC].&[Control] , [Cell].[ABC].&[Core] }
,{[Data].[PQR].&[Yes])}
,[Measures].[A]
)
Is above workable or what will be its syntax
Uhmm maybe something like:
CREATE MEASURE [Measures].[SpecialRate]
AS
AGGREGATE({[Cell].[ABC].&[Control],[Cell].[ABC].&[Core]}, [Measures].[Rate])
- AGGREGATE(EXCEPT([Cell].[ABC].MEMBERS,{[Cell].[ABC].&[Control],[Cell].[ABC].&[Core]}), [Measures].[Rate])
/ AGGREGATE({[Cell].[ABC].&[Control],[Cell].[ABC].&[Core]}, [Measures].[Rate])
,VISIBLE = 1;
The easiest way is to redesign the Cell dimension to include a new rollup column which includes both Control and Core into one rollup.
If that's not feasible and you have to do it in MDX then one way is to create a calculated measure on the dimension and then use it:
CREATE MEMBER CurrentCube.[Cell].[ABC].[All].[Control and Core] as
AGGREGATE({[Cell].[ABC].&[Control], [Cell].[ABC].&[Core]})
,VISIBLE=0;
CREATE MEMBER CurrentCube.[Cell].[ABC].[All].[Not Control and Core] as
AGGREGATE(-{[Cell].[ABC].&[Control], [Cell].[ABC].&[Core]})
,VISIBLE=0;
CREATE MEMBER CurrentCube.[Measures].[My Calc] as
(([Measures].[Rate], Cell].[ABC].[All].[Control and Core])
- ([Measures].[Rate], Cell].[ABC].[All].[Not Control and Core]))
/ ([Measures].[Rate], Cell].[ABC].[All].[Control and Core]);

How to get rank of products in marketwise in ssas

I have dimension hierarchy like Market-->group1-->group2-->product.
I want rank of Group2 members for particular Market on basis of a measure.
Try using the following mdx function:
Rank : https://msdn.microsoft.com/en-us/library/ms144726.aspx

Filtering dimensions in MDX inside a SUM

I am new to MDX expressions and I am trying to create one that sums the value of a given measure filtered by dimensions.
In my database I have several different dimensions that have the same name: "Answer". To sum them up, I have created the query below:
WITH MEMBER Measures.Total as SUM ({[Activity].[Activity].&[14], [Activity][Activity].&[22]},
[Measures].[Activity time])
SELECT NON EMPTY [Measures].[Total] on COLUMNS from [My Analytics]
This query works, however I had to use the "&[14]" and "&[22]" statments that correspond to two different "Answer" dimensions.
Since I have more than two dimensions with the same name, is there a way to rewrite the query above in a way that I would select all these dimensions without having to add their unique ID? For example, I would re-write the query as something like this:
WITH MEMBER Measures.Total as SUM ({[Activity].[Activity].&["Answer"]},
[Measures].[Activity time])
SELECT NON EMPTY [Measures].[Total] on COLUMNS from [My Analytics]
Is this possible?
Thanks!
You can use the Filter function as following:
with
set [my-answers] as
Filter( [Activity].[Activity].members,
[Activity].[Activity].currentMember.name = 'Answer'
)
member [Measures].[Total] as Sum( [my-answers] )
...

Moving Annual Total SSAS

I have a cube and I want to create a MAT column. This column is then expected to show up in the same way as a regular metric would.
How do I create a column that is a Moving Annual Total in SSAS?
A walkthrough / demo would work as well.
Since you haven't really specified anything (MDX or actually in your cube) I will assume you mean in your cube. If i were you I would write a calculated member and then slide it over when browsing or in your reports. It would be something like this
WITH
MEMBER
[Measures].[Rolling Total]
AS
'SUM ( { [Time].CurrentMember.Lag(3) : [Time].CurrentMember },
[Measures].[Warehouse Sales])'
Then you could do something like this:
SELECT
CrossJoin({ [Time].[Quarter].Members },{[Measures].[Warehouse Sales],
[Measures].[Rolling Total]}) ON COLUMNS,
{[Warehouse].[All Warehouses].[USA].Children} ON ROWS
FROM
[Warehouse]