Saturday, February 25, 2012

can I use an attribute in a calculation?

i have an instrument dimension. the instrument dimension has a conversion ratio attribute (i.e. each instrument has a conversion ratio). the conversion ratio attribute is not interesting for analysis in itself, but is often used in calculations.

I want to say somehting like this:

for all instruments, show me sum of [measures].[Price] * ~ CONVERSION RATIO OF THAT INSTRUMENT ~

this actually works ok at the detail level. however, when I start rolling up instruments into say, sectors, then i get a type mismatch error saying that teh "All" member cannot be converted to type double.

In general, is it valid to use a non-measure group dimension attribute to perform a calculation? If not, should any attribute that might participate in a calculation be created as a measure (even though it has no real analysis value by itself). Or should I do the

"Fact * Looked Up Attribute"-type calculation in the DSV and create a new Fact called something like [Price X Conv Ratio]?

The first of these queries generates the error you mention above. I believe the second handles the logic in the manner you are wanting. I haven't had a lot of time to look at this, so I would highly recommend you independtly verify the results of this logic (or the version you implement) to make sure the values are correct. Also, I used a SUM function to aggregate the values in the calculated member. There are a number of functions available to you. In this situation, AVG may be more appropriate.

Thanks,
Bryan

Code Snippet

withmember Measures.[x] as

[Measures].[Reseller Sales Amount]/[Product].[List Price].CurrentMember

select

{[x],[Reseller Sales Amount]} on 0

from [Adventure Works]

;

withmember Measures.[x] as

SUM(

[Product].[List Price].[List Price].Members,

([Product].[List Price].CurrentMember, [Measures].[Reseller Sales Amount])/

[Product].[List Price].CurrentMember.MemberValue

), format="#,#"

select

{[x],[Reseller Sales Amount]} on 0

from [Adventure Works]

;

No comments:

Post a Comment