SUM up 4 measures in SSAS - ssas

I want to sum up 4 measures in SSAS and divide the total by 1 measure
my code is as follows.
=Sum((Fields!Unique_Visits.Value)+Sum(Fields!Ask_the_Expert.Value)
+Sum(Fields!SSMembers.Value)+Sum(Fields!Poll_Members.Value))/
Sum(Fields!EnrolledMembers.Value)

If your measures are defined as using the SUM aggregate function (which is the default) then Analysis Services will do the summing for you and you just need to add the measures together and do the division
([Measures].[Unique Visits] + [Measures].[Ask the Expert] + [Measures].[SSMembers] + [Measures].[Poll_Members] ) / [Measures].[Enrolled Members]

Related

Create Calculate Measure Based On One Dimension And 2 Relations In SSAS

Please Consider this Fact Table:
Sender Receiver Amount
----------------------------------------
Reseller1 Resseler2 100
Reseller1 Resseler3 200
Reseller3 Resseler1 150
Reseller3 Resseler2 50
Reseller1 Resseler4 100
Reseller4 Resseler2 350
Reseller4 Resseler1 500
Reseller4 Resseler3 250
I want create a calculate Measures based on this formula: Sum(Receiver)-Sum(Sender) and create such this result:
Reseller Amount
---------------------------
Reseller1 250 <---- (500 + 150) - (100 + 200 + 100)
Reseller2 500 <---- (100 + 50 + 350) - (0)
Reseller3 250 <---- (200 + 250) - (150 + 50)
Reseller4 -1000 <---- (100) - (350 + 500 + 250)
How can I create calculate measure for this?
Thanks
My DimReseller is:
ResellerCode ResellerName
---------------------------------------
1 Reseller1
2 Reseller2
3 Reseller3
4 Reseller4
and it has two relationship with Sender and Receiver
Edit 1)
Based on Master #Saeid Yousefi's answer:
My structure is:
I wrote this MDX query:
WITH
MEMBER SenderAmount AS
[Measures].[Amount], FORMAT_STRING = "Standard"
MEMBER ReceiverAmount AS
(LinkMember
([Sender].[Hierarchy].CurrentMember, [Receiver].[Hierarchy])
,[Measures].[Amount]), FORMAT_STRING = "Standard"
MEMBER DiffAmount AS
ReceiverAmount - SenderAmount, FORMAT_STRING = "Standard"
SELECT {SenderAmount, ReceiverAmount, DiffAmount} ON 0,
[Sender].[Hierarchy].MEMBERS ON 1
FROM [Reseller Sales]
but I got null for receiver amount:
I know there is a small problem but I can't fix that!
Sample approach to your task:
In DSV - create two tables (as SQL named queries) with Sender - Amount and Receiver - Amount columns. Thus you effectively split Sellers and Receivers data.
On Cube - create two measure groups with Sum aggregation on Amount column and linked to DimReseller dim.
Create a Calc measure as [Measures].[Receiver Amount] - [Measures].[Sender Amount]
Sometimes in a data warehouse a dimension is connected to a fact table in more than one way, these ways can be created using direct or indirect links between Dim and Fact, therefore we can use a dimension to analyze Fact values in different roles; these dimensions are called Role-Playing Dimensions.
When designing a cube, for each role of the dimension, a new instance of dimension will be added to the cube.
Given these circumstances, each dimension will analyze the cube and although you can use multiple dimensions in a report but in Members level these dimensions are distinguished. With these said, sometimes we feel the need to select a member to be the representative of all roles of a dimension given the situation, this is when Link Member function jumps in to aid us.
This function takes two arguments:
Member Expression: An MDX expression which returns a member.
Hierarchy Expression: An MDX expression which returns a hierarchy.
This function returns the member equivalent to a specified member in a specified hierarchy.
So, your code should be something like following:
WITH
MEMBER SenderAmount AS
[Measures].[Amount], FORMAT_STRING = "Standard"
MEMBER ReceiverAmount AS
(LinkMember
([Sender].[Hierarchy].CurrentMember, [Receiver].[Hierarchy])
,[Measures].[Amount]
,[Sender].[Hierarchy].[All]), FORMAT_STRING = "Standard"
MEMBER DiffAmount AS
ReceiverAmount - SenderAmount, FORMAT_STRING = "Standard"
SELECT {SenderAmount, ReceiverAmount, DiffAmount} ON 0,
NON EMPTY [Sender].[Hierarchy].MEMBERS ON 1
FROM [Cube]
Please pay attention to LinkMember function which is working on role-playing dimensions. So, [Sender] and [Receiver] are the names of your dimensions which are attached to your cube, you can find the name of those in Dimension Usage tab of your cube. Also, [Hierarchy] is the name of your attribute or standard hierarchy, so according to the screenshot of your dimension configuration, it should be [Dimension Name] + either [Hierarchy].[Reseller Code].members or [Reseller Code].members or [Hierarchy].members depending on what you want.

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

Common calculated measure across all dimensions

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.

Add percentages to an OLAP cube Mondrian schema

I would like to calculate percentage of one of my measures.
For example:
I have a measure with aggregator distinct-count.
I would like to calculate the percentage of that measure, based on the current information.
For example: gender users-distinct-count percentage
male 25 25% (25/100)
female 41 41% (41/100)
unk 34 34% (34/100)
But, if I filter out unk, I want the percentage to be out of 25+41, i.e. 66
gender users-distinct-count percentage
male 25 37.8% (25/66)
female 41 %62.2 (41/66)
I also want, that when viewing the data with different dimensions, the total sum will be updated accordingly.
I tried this:
<CalculatedMember name="user_percentage" caption="Users Percentage"
formula="[Measures].user_count/ ([Measures].user_count,[dim1].[All Dim1],[dim2].[All Dim2])" dimension="Measures" visible="true">
</CalculatedMember>
but, when filtering values on the dimensions (like removing the
"unk", the total remains the same (over all dim).
Thanks,
You should do it at the client level, not the schema level.
The schema has no idea what you're querying on your rows or columns, only the client does.
Some client tools allow you to create a calculated measure as a % of the visible values, but that has to be done by the query.
Example:
With
SET ROWSET as {[Gender].[Male],[Gender].[Female]}
MEMBER [Gender].[Visible] as Aggregate( ROWSET, [Measures].[user_count] )
MEMBER [Measures].[Percentage] as ( [Measures].[user_count], [Gender].CurrentMember ) / ( [Measures].[user_count], [Gender].[Vislble] )
SELECT
ROWSET on Rows,
{ [Measures][user_count], [Measures].[Percentage] } on Columns
FROM [My Cube]
As you must reference the set selected on rows when defining the percentage, you cannot define it at the schema level.

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?