I am relatively new to SSAS MDX and am facing the problem to create aggregates over all measures of different dimension members. The following picture best describes what I'm trying to achieve: Problem and What the solution should be
This is a draft and a simplification of a more complex scenario, so don't bother ;-). After running a series of experiments I figured out to use a simple dimension without connection to other dimensions to be able to use the SCOPE statement to override the produced results in the report. The simple dimension "Kurz PuL" contains the preceding members (Umsatz .. Periodenergebnis) and shall produce the Profits + Loss report.
What currently works is to show results of single members (like Umsatz, Wareneinsatz, SbA, Personal). But I am not able to aggregate values of more than one member to obtain an aggregate, e.g.: of Umsatz + Wareneinsatz = Rohertrag. I tried different approaches but none worked. See the following SCOPE statements which are used to "override" the resulting values that are displayed in Excel (first image ^^):
SCOPE Statements:
/*
The CALCULATE command controls the aggregation of leaf cells in the cube.
If the CALCULATE command is deleted or modified, the data within the cube is affected.
You should edit this command only if you manually specify how the cube is aggregated.
*/
CALCULATE;
SCOPE ([Kurz PuL].[Calculated].[Umsatz]);
THIS = AGGREGATE([EinfacheBwaZeile].[Hierarchy].&[U]);
END SCOPE;
SCOPE ([Kurz PuL].[Calculated].[Wareneinsatz]);
THIS = AGGREGATE([EinfacheBwaZeile].[Hierarchy].&[W]);
END SCOPE;
/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[Rohertrag]);
THIS = AGGREGATE(FILTER([EinfacheBwaZeile].[Hierarchy].CurrentMember, { [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W] }));
END SCOPE;
SCOPE ([Kurz PuL].[Calculated].[Personal]);
THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[P] });
END SCOPE;
SCOPE ([Kurz PuL].[Calculated].[Marketing]);
THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[M] });
END SCOPE;
/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[Deckungsbeitrag]);
THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
, [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D] });
END SCOPE;
SCOPE ([Kurz PuL].[Calculated].[SbA]);
THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[S] });
END SCOPE;
/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[EBITDA]);
THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
, [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D]
, [EinfacheBwaZeile].[Hierarchy].&[S], [EinfacheBwaZeile].[Hierarchy].&[A] });
END SCOPE;
/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[EBIT]);
THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
, [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D]
, [EinfacheBwaZeile].[Hierarchy].&[S], [EinfacheBwaZeile].[Hierarchy].&[A]
, [EinfacheBwaZeile].[Hierarchy].&[I] });
END SCOPE;
/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[EBT]);
THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
, [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D]
, [EinfacheBwaZeile].[Hierarchy].&[S], [EinfacheBwaZeile].[Hierarchy].&[A]
, [EinfacheBwaZeile].[Hierarchy].&[I]
, [EinfacheBwaZeile].[Hierarchy].&[T] });
END SCOPE;
/* DOES NOT WORK: */
SCOPE ([Kurz PuL].[Calculated].[Periodenergebnis]);
THIS = AGGREGATE( { [EinfacheBwaZeile].[Hierarchy].&[U], [EinfacheBwaZeile].[Hierarchy].&[W], [EinfacheBwaZeile].[Hierarchy].&[R], [EinfacheBwaZeile].[Hierarchy].&[P]
, [EinfacheBwaZeile].[Hierarchy].&[M], [EinfacheBwaZeile].[Hierarchy].&[D]
, [EinfacheBwaZeile].[Hierarchy].&[S], [EinfacheBwaZeile].[Hierarchy].&[A]
, [EinfacheBwaZeile].[Hierarchy].&[I]
, [EinfacheBwaZeile].[Hierarchy].&[T]
, [EinfacheBwaZeile].[Hierarchy].&[E] });
END SCOPE;
I've been trying to find a resource that explains how to aggregate on more than one member but didn't find a solution. How can I use the AGGREGATE() function to combine/sum values that are related to multiple dimension members of [EinfacheBwaZeile].[Hierarchy].A, … .B, … .C ?
I really appreciate your answers! Thanks in advance, Cordt
-- UPDATE 2019-05-28 as reply to Moaz as of 2019-05-27: -- Hi Moaz, thank you for your suggestion. Sadly, that solution does not meet my needs. First thing to notice is, that I need a SCOPE-Statement, not a SELECT-MDX. Second, I need all the measures of specific members of another dimension to be "summarized". That looks at first sight like a "running total" but it depends on the values of "previous" members where some may be skipped. In words of the Adventure Works sample, the following shows what I need:
SCOPE (MountainBikeSales);
THIS = AGGREGATE(Product.&[Bikes]);
END SCOPE;
SCOPE (BikesAndAccessories);
THIS = AGGREGATE({ Product.&[Bikes], Product.&[Accessories] });
END SCOPE;
SCOPE (BikesAccsClothing);
THIS = AGGREGATE({ Product.&[Bikes], Product.&[Accessories], Product.&[Clothing] });
END SCOPE;
Is that more clear? You could even think of a SCOPE that skips Accessories by summarizing Bikes and Clothing instead of Accessories. Problem to me is, that the first statement would succeed (that summarizes a single member) but the others won't.
Thank you for your advice! Cordt