I have an OLAP Cube in which there is a Parent-Child Account Dimension.
My goal is to set a certain measure value on the GROSS-PROFIT Account , with a certain logic :
GROSS PROFIT = REVENUES - COSTS
GROSS PROFIT is the parent of REVENUES and COSTS in my account hierarchy, and now the measure shows me the sum (obviously) , not the substraction.
The measure is named [Measures].[Report]
I don’t know how to return, in my measure, the substraction only for the GROSS PROFIT Account , so please help me.
Tks a lot
Daniel
I solved the problem , I saw that exists an “operator column” in the dimension definition, that permits to perform some operation like substraction and addition between members only specifying a certain value column (setted for ex to “+” or “-“)
Related
I am trying to gather various KPI's for salespersons in multiple stores. The goal is to break down store performance into salesperson level.
I am facing an issue when trying to add a hitrate, as this is normally only by store. Number of quotes given / Visitors.
Even though it may not be 100% accurate I still wish to have the KPI by sales person. I am able to do this on a sales person level, but my subtotal for the store is incorrect, as it makes a summation of visitors by sales persons.
Monthly period is to be considered to as sales persons comes and goes throughout the period. Example of what I wish for a Subtotal for the measure "Vis". Store X 370 for month 1,2 & 3. For Store Y 395.
Vis measure = Visitor (Calculation i have tried but gives the wrong result for the store total for the period.)
I have tried various Calculate, Sum, max functions, but nothing seems to provide the result I need.
I hope that someone might be able to help me get along with this.
Example data tables is link as shown below:
enter image description here
Thanks in advance.
This sounds like a case where the HASONVALUE function would be useful.
The idea being that you would the result of that function in an if to determine if you are calculating at your sales person level or a the store level which should contain multiple salespersons. Thus you would have two different calculations, one for the sales person and store combination, and one for the Store level.
Example would be sometime like the following, in this example I am assuming you have a sales person table:
Measure:= IF( HASONEVALUE( Salesperson[Sales Person] ),
[Vis],
[Measure for subtotal]
)
[Measure for Subtotal] would just being the calculation that you want for your store total.
Of course if you filter to just a single sales person, then the totals for the store will just match that sales person.
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.
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])
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?
In the "Calculations" tab of an SSAS cube project, does "Measures" dimension represent all measures within the measure groups as well?
For instance:
Patron Revenue has measures actual win, cash in, cash out....
Patron Redemption has measures operator pay, redeeming dollars, redeeming comp...
In calculation tab,
[Actual Gross Profit] is calculated as
[Measures].[Actual Win]-[Measures].[Operator Pay]-[Measures].[Redeeming Comp]-[Measures].[Redeeming Dollars]
So, in this case, does the [Measures] dimension represent the measures such as actual win, operator pay, redeeming comp and redeeming dollars etc located in different measure groups?
Help appreciated!
Yes.
Just as [Measures] is treated as a dimension, each measure group/measure is treated like a dimension hierarchy/member, so that you can slice and dice in MDX across any "dimension"; this means you can do things like have a query sliced on two dimensions and a measure; with one dimension on rows, then either the measures on columns (with the dimension implicit in the values) or a dimension on the columns, with the measure implicit.