Calculated member, or scope MDX - ssas

I am trying to create a calculated member, which brings up the current members personal balance as a figure, and besides that I would like the show the network balance of the current member. So let's say I am a franchise and I have my personal shop, and also several other affiliated shops which I take care of.
My personal balance would be -> Eur1000
My network balance would be -> my Eur1000 balance + (All my affiliated shops balances)
I have done the personal balance part, however I am trying to create a calculated member within an MDX query to show the network balance, and am getting #Error - so I am doing something wrong. My code is as follows;
with member [Measures].[Network Balance] as
SUM(NULL:DESCENDANTS([Dim User Balance].[UserIdHierarchy].CurrentMember,0,self),
[measures].[balance])
member [Measures].[Peronal Balance] as
SUM(NULL:[Dim User Balance].[UserIdHierarchy].CurrentMember,
[measures].[balance])
Seems to be that the member with member [Measures].[Network Balance] is not liking the descendants function. Any ideas how I can go around this? Does scope work better in this context?
Many thanks!

I do not know what you want to achieve with the NULL : construct.
As far as I understand your description, the Personal Balance is just [Measures].[balance] without any need to adapt that.
And the [Measures].[Network Balance] would just be
Sum(Descendants([Dim User Balance].[UserIdHierarchy].CurrentMember, 0, SELF_AND_AFTER),
[Measures].[balance])

Related

MDX IIF statement to calculate new member basing on measure and hierarchy leaves

I have a simple Data Cube for computing shared expenditures with one measure Amount and some dimensions and hierarchies but interesting one would be Relationship. It describes who bought something for whom. It's structure is:
Who
For whom
Relationship key
I am trying to code a calculation representing debt. For example if I bought something for sharing usage it would be half of 0.5 * Amount. On the other hand, if I bought something for myself it would be 0 * Amount.
As far I tried following calculation:
IIF(
[dimRelationship].[Relationship].currentMember = [dimRelationship].[Relationship].[RelatonshipID].&[MeShared],
[Measures].[Amount]*0.5,
[Measures].[Amount]*0)
It works good only at lowest RelationshipID level. When I roll-up browsered pivot-table it is acting according to else-expression. That is not really surprising because hierarchy's currentMember is not MeShared anymore. Another bad thing that total aggregation work neither - it would be most important as a general summary. Is there any suffix like .LeafMember or something like that which could help me perform this calculation?
Thank you in advance!
Best regards,
Max!
In you fact table add another column, in this column store the "Amount" multiplied by the relationshipID for that particular row. This will address you issue right out the box
Try SCOPE statement.
Firstly, create new calculation [Debt Calculation] as [Measures].[Amount]*0 /* as ELSE-scenario */
Then create a SCOPE:
SCOPE([Debt Calculation],[dimRelationship].[Relationship].[RelatonshipID].&[MeShared]);
THIS=[Measures].[Amount]*0.5;
END SCOPE;
If it's the lowest level of hierarchy and is a dimension key (which is used as a link to measure groups), it will re-calc higher levels of this dimension automatically. Please post a result here if not.

Can you create an SSAS Tabular measure with filter constraints?

I am trying to get my head around how to design the SSAS tabular model for a scenario where I have an attribute on a dimension that will modify an otherwise straight-forward measure on a related fact table.
The fact table is currently at 155 million rows. The dimension has 6200 rows. The measure we need sums a unit volume fact, then multiplies that sum by a factor that belongs to the dimension. The context used for this measure has some constraints, then: the aggregation can never include multiple rows from the related dimension. It doesn't make any business sense to do so.
I started with this, which I know is wrong: =SUM([Unit Volume])*Products[Foo Factor], and of course the designer complains because the related attribute has many values without a specific context.
My work-around for now is to create a calculated column that brings the factor into the fact table: =RELATED(Products[Foo Factor]), and then I can create a measure that looks like this: =SUM([Unit Volume])*AVERAGE([Foo Factor]).
I don't like the idea of putting calculated columns on that fact table. It's huge and it only going to get bigger. I also don't like that there doesn't appear to be a way to put constraints on the context for a given measure so I can ensure the we don't roll up volume across multiple products. Or is there?
It seems to me that ours is not an unusual scenario, but I'm too new to DAX to know how to model it correctly. If I were in my familiar SQL world, I would use a windowing function like this:
select sum([Unit Volume]) over (partition by <context goes here>) as [Unit Volume Total]
Can I create something like this in a measure with DAX?
UPDATE
It seems like this should work, but the designer still barks:
=CALCULATE(SUM('My Facts'[Unit Volume])*Products[Foo Factor],FILTER(Products,Products[Product Code]="0"))
My thought was that the [Product Code]="0" filter would be replaced by the current context and since [Product Code] is defined as the key on the related table, SSAS would know my intent. Alas, it doesn't.
I think I may have it. Seems like I may not be able to get away from using an AVERAGE aggregation on the foo factor, but the HASONEVALUE function does enforce the constraint I want.
This should work:
=
IF (
HASONEVALUE ( Products[Product Code] ),
SUM ( 'My Facts'[Unit Volume] ) * AVERAGE ( Products[Foo Factor] ),
SUM ( [Unit Volume] )
)
Please try this:
=CALCULATE((SUM(My Facts[Unit Volume])*Products[Foo Factor]),Products[Product Code]=0)
Also please confirm Product Code format.

MDX Calculated Member SubCube

I am relatively new to this depth of MDX, but here is my dilemma. My goal is to implement a calculated member using a .Net Stored Procedure. The calculation (XIRR) will be based on a set of cash flow dates and cash flow amounts. Ideally this would be a calculation in my cube that is available as a measure to Excel/Browser users.
So to start simple I am just trying to implement my own COUNT calculated member/measure (not even using .Net) to say count the # of members in a given dimensions based on the current context. So lets say I have a dimensions Customer with a Customer Id Key. And let's say there are a total of 100 customers in my database. So Count(Customer.CustomerId.AllMembers) would be 100. Now when you start using the browser and say filter on Customer.CustomerId.&1, Customer.CustomerId.&2 (customer id 1 and 2) I would expect my count calculated member to return 2 but it returns the total 100 count. I have tried using exists. I am sure there is something that I am just fundamentally not understanding yet.
Hopefully this makes sense, would hugely appreciate any help from someone that has a good understanding of SSAS/MDX and calculations. Thanks in advance.
Marty
You may have some issues here, I did when I tried to do a similar thing.
Your calculated member is not honouring the client sub-select, which is normal. What in theory you would do is create a dynamic set, and then use that in the calculated member to force the dimension count to be evaluated in the context of the subcube your filters have created. Mosha has a good article here: http://sqlblog.com/blogs/mosha/archive/2007/08/25/mdx-in-katmai-dynamic-named-sets.aspx
So you'd end up with something like:
CREATE DYNAMIC SET CurrentCube.Customers AS
EXISTING(Customer.CustomerId.CHILDREN);
CREATE MEMBER CurrentCube.Measures.CustomerCount AS
Customers.COUNT
Now the real problem you'll have is a bug in SSAS https://connect.microsoft.com/SQLServer/feedback/details/484865/calcuated-member-with-a-reference-to-dynamic-named-set-kills-the-cubes-performance so the code above, which will probably work just fine locally, will kill a production cube. This was an exciting learning experience for me.
See if you can get any of the workarounds to work, I couldn't.
I was able to get what I wanted, but I had to create query-scoped dynamic sets as part of the MDX query, I wasn't able to create it as a cube object:
WITH DYNAMIC SET Customers AS
EXISTING(Customer.CustomerId.CHILDREN);
MEMBER Measures.CustomerCount AS
Customers.COUNT
SELECT
Measures.CustomerCount
ON COLUMNS
FROM [Cube]
WHERE Customer.CustomerId.&[1]
Let us know how you get on.

How to transparently show non-additive measures in Analysis Services as if they were additive

In my cube there are certain measures which are non-additive, however I can compute a value for every drill down level. Unfortunately the computation is too complex for it to be done in in Analysis Services.
If I precompute the drill down levels I'm interested in, I have to put those values into a separate fact-table / measure group for each drill down level, or don't I? Is it possible to do this in a way that is transparent to the end user? So it should look like there is only one fact table and SSAS automatically selects the value from the correct fact table based on the drill-down level?
I found the answer in a Microsoft forum: http://social.msdn.microsoft.com/Forums/en-US/sqlanalysisservices/thread/d5998b23-936b-4e7b-b593-bd164b20c022
On the Calculate tab you can define a scope statement:
In this really trivial example, internet sales amount will be shown when reseller sales amount is chosen (at calendar quarters).
scope([Measures].[Reseller Sales Amount], [Date].[Calendar].[Calendar Quarter]);
this=[Measures].[Internet Sales Amount];
end scope;

SSAS - Need to have a calculated member that uses as a denominator one particular dimension value

I have a cube that I built in SSAS for general ledger data. The cube uses 2 fact tables. One for accounts that are "normal" dollar based accounts and the other is for unit / statistical accounts - accounts that count ANYTHING, except for money usually.
I need for one calculated member in SSAS to be ANY of the "normal" dollar based accounts divided by ONLY one particular dimension of the statistical accounts.
If clear as mud - let me give the specific example. There is an statistical account called Gallons (measure is units) and there are many accounts such as sales, depreciation, tax expense, etc that are the "normal" G/L accounts (measure in dollars). I need to have the cube be able to report on ANY of the "normal" G/L accounts DIVIDED by Gallons (so that any of the normal revenue / expense accounts can have a measure that shows BY GALLON.)
I have no clue how to write the MDX to do this (the function to use and / or the syntax) and I have tried many times and researched quite a bit (I am a SQL person - FAR from a MDX person I guess!). I'm thinking I need to use FILTER but I'm not even sure that is the right direction.....
Little unsure with your design ,If you are having trouble with MDX you can create a calculated member in DSV using T-sql