G&#246&#59;ran


Hi,

can someone help me write a calculated measure that shows:

all customers / all customers we sold an article to

I guess that I need some form of crossjoin or something...

someone have any idea that you want to share with me Smile

Code Snippet

count ([Customer].[Customer].members) / [ ]





Re: MDX calculated measure

Bryan C. Smith


So, there are two parts. First, you need to come up with a value for all customers. Then, you need to come up with a value for active customers. There is also the issue of context to consider. In other words, if my query breaks down data by product, do I want to return just the count of customers who purchased that product

Well, I've got a simple example here. It does not address the context issue described above. Still, it should provide you a starting point.

Code Snippet

with member [Measures].[Reseller Count] as

COUNT([Reseller].[Reseller].[Reseller].Members)

member [Measures].[Active Reseller Count] as

COUNT(

EXISTS(

[Reseller].[Reseller].[Reseller].Members,

[Reseller Sales Order Details].[Sales Order Number].[Sales Order Number].Members,

'Reseller Orders'

)

)

member [Measures].[Active Resellers Percent] as

[Measures].[Active Reseller Count]/[Measures].[Reseller Count]

, format="0%"

select

{[Measures].[Reseller Count], [Measures].[Active Reseller Count], [Measures].[Active Resellers Percent]} on 0

from [Adventure Works]

Good luck,

Bryan







Re: MDX calculated measure

Göran

Thanks Bryan,

I will try something like you described above. Do you know if there is a way to get a value from a specific level in the hierarchy

I can get the values I need but I have a problem to write the mdx question that will give me the percent value as answer.

With one of these code samples I get the values that I want to divide in the calculated measure (They give the same result)

1.

Code Snippet
distinctcount
([Customer].[Customer].members)

2.

Code Snippet

COUNT(CROSSJOIN({[Measures].[Sales]},

{[Customer].[Customer].members}), EXCLUDEEMPTY)

For example:

Vendor1 10

Article1 8

Article2 5

Article3 10

Vendor2 26

vendor3 54

Vendor1 have a total of 10 customers and Article1 are sold to 8 of those customers, Article2 to 5 and Article3 are sold to all 10 of the customers.

What I want to do is to have a calculated measure that divides Article1 value with Vendor1 value(8/10), Article2 value with Vendor1 value (5/10) and so on.

The values are from the same code sample so Vendor1s value of 10 uses the same code as the Article1s value (distinctcount([Kund].[Kund].members))

And

Code Snippet
distinctcount([Customer].[Customer].members) / distinctcount([Customer].[Customer].members)

wont work of course Smile

I want to have a calculated measure that dont change when I drill down Vendor. Like:

A B

Vendor1 10 10

Article1 8 10

Article2 5 10

Article3 10 10

Vendor2 26 26

Vendor3 54 54

Then I just need to divide A / B*100 and I have the value that I need.

If someone knows how to do this I would be very happy Smile







Re: MDX calculated measure

Bryan C. Smith

Take a look at this sample. I calculate Reseller Count as the count of resellers associated with this category. I then do a count of Resellers at the category's parent. The IIF() statement is used to handle the fact that the "ALL" level doesn't have a parent. I then calculate and format a ratio.

Hope this helps,
Bryan

Code Snippet

with member [Measures].[Reseller Count] as

COUNT(

EXISTS([Reseller].[Reseller].[Reseller].Members,[Product].[Category].CurrentMember,'Reseller Sales')

)

member [Measures].[Parent Reseller Count] as

COUNT(

EXISTS(

[Reseller].[Reseller].[Reseller].Members,

IIF(

ISEMPTY([Product].[Category].CurrentMember.Parent),

[Product].[Category].CurrentMember,

[Product].[Category].CurrentMember.Parent

),

'Reseller Sales'

)

)

member [Measures].[Ratio] as

[Measures].[Reseller Count]/[Measures].[Parent Reseller Count]

,format="0%"

select

{

[Measures].[Reseller Count],

[Measures].[Parent Reseller Count],

[Measures].[Ratio]

} on 0,

[Product].[Category].Members on 1

from [Adventure Works]






Re: MDX calculated measure

Göran

Thanks Bryan,

I¡¯m new to MDX so I didnt knew there was a CurrentMember.Parent command. I guess that is what I¡¯ve been looking for Smile

Your code sample helped me alot.

Thanks again!






Re: MDX calculated measure

Göran

Calculation CustomerCount

Code Snippet
distinctcount
([Customer].[Customer].members)

Calculation

Code Snippet

iif(([Measures].[CustomerCount],[Article].[Articlegroup - Article].parent)=0,NULL,(([Measures].[CustomerCount])/([Measures].[CustomerCount],[Article].[Articlegroup - Article].parent)))

Now I have solved the problem. This is the two calculations I came up with. The first calulation counts all the customers that the vendor have and the other calculation uses that calculation and its parent to get the percent value.