简体   繁体   中英

SSAS Calculated dimension member

I try to add a calculated member to a cube,

Currently in my report, I have something like this

dimension value
a         5
b         10

I try to add one calculated member x (= a/b)

dimension value
a         5
b         10
x         0.5

This works in management studio:

    with member [dimension].[hierarchy].[x] as
    ( [Measures].[Value], [dimension].[hierarchy].[a])/
    ([Measures].[Value], [dimension].[hierarchy].[b])

    select [Measures].[Value]
    on 0
    ,
    {
    (
    [dimension].[hierarchy].[a]
    ,[dimension].[hierarchy].[b]
    ,[dimension].[hierarchy].[x])
    } on 1
    from [cube]
    where { [Date].[Date].&[20140821]}

But in the cube - calculated member, I tried assign the calculated member to [dimension].[hierarchy], in browser, I can see the x under [dimension].[hierarchy] together with 'All' member. But when I right click it, there is only option to add it to subcube, but I want it to be added to row area.

I know I can create calculated measure instead of calculate dimension, so it will be something like this:

dimension value x
a         5     0.5
b         10    0.5

but it's confusing for users.

I am novice, so is this doable (calculated dimension member)? and how?

A few years late to the party here!

However this is a common requirement when processing financial data. Typically for a P&L report there will be a set of metrics which need to be added to the same dimension table so that the rows come out in the correct order on, especially if using SSRS. Metrics typically are ratios such as Average Weekly Fee.

You are wanting to calculate a ratio. A very powerful way of doing this is to use the SCOPE statement in the SASS cube calculations. The Scope statement can effectively inject a calculated value against a dimension value that will automatically recalculate depending on the time dimension in any MDX queries you subsequently write.

For example the value of a/b for a given month will differ from that for a given quarter. X of course needs to exist in the dimension even if it has no value initially. Our scope statement would look something like this:

SCOPE ([Measures].[Value], {[dimension].[hierarchy].[x]});
   This = IIF([dimension].[hierarchy].[b] = 0, null,
   [dimension].[hierarchy].[a]/[dimension].[hierarchy].[b];
END SCOPE;

Whilst [Measure].[Value] is defined for the whole dimension based on an underlying related fact table, we are only altering the measure value associated with x and also catering for the possibility that b could be zero.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM