Page 1 of 1

Calculating subtotals using MDX

Posted: Fri Mar 26, 2010 12:13 pm
by bancika
Hi,

I have the following query:

Code: Select all

SELECT
 { { [Measures].[Unit Sales]} } ON COLUMNS,
 { CrossJoin([Gender].[Gender].Members, [Marital Status].[Marital Status].Members) } ON ROWS
FROM Sales
It returns data grouped by gender, then by marital status. How can I calculate me Unit Sales total but for Gender?

I tried with something like this

Code: Select all

WITH MEMBER [Measures].[Unit Sales Subtotal Gender] AS
SUM({[Gender].CurrentMember}, [Measures].[Unit Sales])
SELECT
 { { [Measures].[Unit Sales],  [Measures].[Unit Sales Subtotal Gender]} } ON COLUMNS,
 { CrossJoin([Gender].[Gender].Members, [Marital Status].[Marital Status].Members) } ON ROWS
FROM Sales
but it doesn't work, although I'm using [Gender].CurrentMember I still get the same numbers broken by marital status. Here's the result (through JPivot)

Image

What I want to have is something like this (values circled in red are ones I want to calculate):

Image

Thanks in advance,
Bane
Edit/Delete Message

Re: Calculating subtotals using MDX

Posted: Sun Mar 28, 2010 12:06 pm
by Marcus Scherer
Hi Bane,
if you are referring to the mondrian example, don't ignore the already existing parent levels (e.g. "All Marital Status"):

your statement is:

select {[Measures].[Unit Sales]} ON COLUMNS,
{Crossjoin([Gender].[Gender].Members, [Marital Status].Members)} ON ROWS
from [Sales]

Try out what happens if you use [Gender].Members instead of [Gender].[Gender].Members also.

Ciao,
Marcus

Re: Calculating subtotals using MDX

Posted: Fri Jun 24, 2011 6:27 pm
by noezavala
Use this:

WITH MEMBER [Measures].[Unit Sales Subtotal Gender] AS
([Gender].CurrentMember, [Marital Status].CurrentMember.Parent, [Measures].[Unit Sales])
SELECT
{ { [Measures].[Unit Sales], [Measures].[Unit Sales Subtotal Gender]} } ON COLUMNS,
{ CrossJoin([Gender].[Gender].Members, [Marital Status].[Marital Status].Members) } ON ROWS
FROM Sales