Common calculated measure across all dimensions - ssas

I have a cube with 4 dimensions and I have a measure called Transaction Count. Now I want to calculate the Percentage across all the dimensions for that above measure.
I also have a dimension called Cars. I have the count across all the Cars and now I have defined a calculated measure for calculating the Percentage of each car from the total number of transactions. But it will work only for that particular dimension.
How I can create a single percentage calculated measure which can be used across all the dimensions?
MDX for the calculated measure: (which is working for only Carmake dimension)
CASE
WHEN ISEMPTY( [MEASURES].[Trans COUNT] )
THEN 0
ELSE ([Dim Car Make].[Hierarchy].CURRENTMEMBER,
[MEASURES].[FACT COLORPERFORMANCE COUNT])/
( [DIM CAR MAKE].[CARMAKE].[(ALL)].[ALL],
[MEASURES].[Trans COUNT])
END
I already have a Trancount(1000) measure. Now I need to create a calculated measure Freq % which should be calculated across all the dimensions.
Screenshot -> http://i.stack.imgur.com/iuaQO.jpg (need 10 rep for posting images)
Table 1 in screenshot - you drag and drop the carmake dimension, then both Tran Count and Freq% should be calculated as per CarMake breakdown.
Table 2 in screenshot - you remove CarMake and drag Quality, then both Tran Count and Freq% should be calculated as per Quality breakdown.
Table 3 in screenshot - you remove Quality and drag Brand, then both Tran Count and Freq% should be calculated as per brand breakdown.

The best way i found is using AXIS() to dynamically get the currently used dimension.
with
member Member_Lvl as AXIS(0).item(0).level.ordinal --get the level for next calc
member All_Member as sum(ancestor(axis(0).item(0).hierarchy.currentMember,<yourMeasure>),Member_Lvl )
member Percent_of_All as sum(axis(0).item(0).hierarchy.currentMember,<yourMeasure>) / All_Member
select <Your Dim > on 0, {<Your Measure>, Percent_of_All} on 1
from <Your Cueb>
NOTICE: replace the SUM function on the calculations if you need other aggregation.

Related

Complex Filter on SSAS calculated Member

I Tried to create a calculated measure inn my SSAS cube with complex filters as the following:
([Measures].[Amount],[Scenarios].[Scenario Key].&[1],[AccountType],[AccountType].[Account Type].&[Bank],[AccountType].[Account Type].&[Cash],[AccountType].[Account Type].&[NotesReceivable],[JE Type].[JE Type].&[CI],[JE Type].[JE Type].&[NR])
I want to Get the summation of amount value which has:
Scenario Key = 1
Account Type IN ("Bank","Cash","NotesReceivable")
JE Type IN ("CI","NR")
But i Get this measure as Null So can any one can help to solve this?
It's not working because you are doing an intersection of the same dimension hierarchy:
[AccountType].[Account Type].&[Bank],[AccountType].[Account Type].&[Cash]
means in MDX: Account Type = Bank AND Account Type = Cash at the same time.
Just use set of members and SUM function.
Try this one:
SUM(
{[AccountType].[Account Type].&[Bank]
,[AccountType].[Account Type].&[Cash]
,[AccountType].[Account Type].&[NotesReceivable]}
*
{[JE Type].[JE Type].&[CI]
,[JE Type].[JE Type].&[NR]}
,([Scenarios].[Scenario Key].&[1],[Measures].[Amount]))
Explanation:
SUM - aggregate function
Dimension1 filter * Dimension2 filter - gave all combinations
(Dimension3,measure) - filters out single-selected dimensions

Create a Calculated Member to remove need to load pre calculated measure

I am trying to replicate the following sql statement into MDX so that I can create a calculated member in the cube using the base loaded members instead of having to calculate it outside the cube in the table and then loading it
SUM(CASE WHEN ((A.SALES_TYPE_CD = 1) AND (A.REG_SALES=0))
THEN A.WIN_SALES
ELSE 0
END) AS Z_SALES
I am currently loading SALES_TYPE_CD as a dimension and REG_SALES and WIN_SALES as measures.
I also have a few other dimensions in the cube but for simplicity, lets just say I have 2 other dimensions, LOCATION and ITEM
The dimension has LOCATION has 3 levels, "Region"->"District"->"Store", ordered from top to bottom level.
The dimension has ITEM has 3 levels, "CLASS"->"SUBCLASS"->"SKU", ordered from top to bottom level.
The dimension has SALES TYPE has 2 levels, "SALES_TYPE_GROUP"->"SALES_TYPE_CD", ordered from top to bottom level.
I know that I cannot create a simple calculated member in the cube which crossjoins the "SALES_TYPE" dimension with another dimension to get the answer I want.
I would think that it would be a more complicated MDX statement something like :
CREATE MEMBER CURRENTCUBE.[Measures].[Z_Sales]
AS 'sum(filter(crossjoin(leaves(), [Sales Type].[Sales Type].
[Sales_Type_CD].&[1]), [Measures].[REG_SALES]=0),[Measures].
[WIN_SALES])',
FORMAT_STRING = '#,#',
VISIBLE = 1 ;
But this does not seem to return the desired result.
What would be the proper MDX code to generate the desired result?
I did a bunch of testing with the data and I now know that there is no way I can get the right answer by using MDX alone in this scenario. Like "Greg" and "Tab" suggested, the only way would be to have reg sales as a dimension. Since this is a measure, that is out of the question because of the large number of possibilities for the value which has a data type of decimal (18,2)
Thanks for taking the time to answer the question.

SSAS new measure with a fixed dimension value

I am trying to create a measure in SSAS 2012 that looks something like that in MDX:
SELECT
{[Measures].[DWH FACT Events Count]} ON COLUMNS
FROM [27BI]
WHERE
[DWH DIM Event Name].[Event Name].&[wizard_done-button_click];
This gives me the result of counting rows (DWH FACT Events Count) when the Event Name is fixated to be "wizard_done-button_click".
I want this measure to update on each slice of the cube (i.e choose a country). While this query works, I don't know how to get it to become an actual measure.
One solution I saw was to create a Calculation:
CREATE MEMBER CURRENTCUBE.[Measures].[WizardDone]
AS
(
[Measures].[DWH FACT Events Count] ,
[DWH DIM Event Name].[Event Name].&[wizard_done-button_click]
)
This calculated member gives me the result I want, but it doesn't update when I browse the cube and try to slice it by different dimensions.

SSAS & OLAP cube: twice same measure

I'm not very experienced in OLAP Cube + MDX, and I'm having a hard time trying to use twice the same measure in a cube.
Let's say that we have 3 Dimensions: D_DATE, D_USER, D_TYPE_OF_SALE_TARGET and 3 tables of Fact: F_SALE, F_MEETING, F_SALE_TARGET
F_SALE is linked to D_USER (who make the sale) and D_DATE (when)
F_SALE_TARGET is linked to D_USER, D_DATE, D_TYPE_OF_SALE_TARGET (meaning: user has to reach various goals/targets for a given month).
I can browse my cube:
Rows = Date * User
Cols = Number of sale, Total amount of sale + the value of 1 target (in the WHERE clause, I filter on [Dim TYPE SALE TARGET].[Code].&[code.numberOfSales])
How can I add other columns for other targets? As all the targets are in the same table, I don't see how to add a second measure from [Measures].[Value - F_SALE_TARGET] linked to a different code, ie. [Dim TYPE SALE TARGET].[Code].&[code.amountOfSale].
your question is not clear to me but it seems like one way to accomplish that is by creating Calculated Members. Basically, select you cube in BIDS, go to the Calculations tab and create Calculated Members. You would be able to insert your MDX query there. For each target type you can create a different calculation such as: ([Measures].[Value - F_SALE_TARGET], [Dim TYPE SALE TARGET].[Code].&[code.amountOfSale])

Ignore associated NULL values in SSAS calculated member

I'm creating Analysis Services cubes in Visual Studio BIDS, and have a question about summing in calculated members.
The data has to do with commercial real estate transactions. I want to sum square feet of building space involved in sales transactions for each region. I'm going to use that result in a weighted average calculation. However, I only want to sum the square feet of transactions which have non-null values for the corresponding building capitalization rate (cap rate) member.
Here is a drill-down to Athens in the cube browser:
Note that Athens has 15 values for square feet, but only 5 values for cap rate, reflecting my relational data source as shown here:
So, I only want to sum the five square feet values that have associated cap rate values. Doing the math with the relational query result above you can see that this should result in a sum just over 900K, not the 2 million+ sum shown in the BIDS screenshot.
My attempt at this calculation:
sum(
descendants(
[Property].[Property by Region].CurrentMember,
[Property].[Property by Region].[Metro Area]
),
iif([Measures].[Cap Rate] is null or [Measures].[Sq Ft] is null, 0,
[Measures].[Sq Ft])
)
ends up including the square feet values that have no corresponding cap rates, so I still end up with a value in the 2 millions.
Why is my iff() clause not working as one would expect?
I was finally able to create the weighted average calculation using a combination of Named Calculations in the Data Source View (DSV) and a calculated member (in the cube script). First, I went to the DSV and added a named calculation called xWeightedCapRt with a formula as follows:
CASE WHEN CapRate IS Null THEN Null Else CapRate * SqFt END
In the cube, I then added xWeightedCapRt as a New Measure. I set its aggregation function to Sum and left its Visible property set to True temporarily.
I created an additional Named Calculation called "xSqFt", defined as:
CASE WHEN CapRate IS Null THEN Null Else SqFt END
and again created a corresponding measure.
On the Calculation tab (of the cube designer) I created a new calculated member, [WAvg Cap Rate by Sq Ft], with the following formula:
[Measures].[x Weighted Cap Rt] / [Measures].[x Sq Ft]
After deploying and processing the cube, I was able to verify that the weighted average calculation matched my spreadsheet numbers. At that point, I set the Visible property of the two intermediate measures to False and redeployed.
What I've learned is that calculations at the "row-level" are best performed through the DSV. You can then use those to build up more complex calculations within the cube.
(NOTE: One thing that needs to be added to the steps above is logic to handle division by zeros.)
Couldnt you have done a nonempty around the descendants on the cap rate measure?