How to go from rows to a hierarchy in icCube - mdx

I want to create a one-column hierarchy from multiple columns using mdx. I got this result:
from the Sales cube with this mdx:
SELECT
{ {[Measures].[Amount]} } ON COLUMNS,
{ [Customers].[Geography].firstNotAllLevel().allmembers }*{ [Product].[Product].[Category].allmembers }*{ [Time].[Quarter].firstNotAllLevel().allmembers } ON ROWS
FROM [Sales]
I want the first three columns to form a hierarchy that looks like this:
Is this possible in icCube using mdx? If it is, can you show me how?

Using standard MDX you can't solve the problem as you can not navigate across hierarchies on a single MDX statement.
What we're looking for is to define our own hierarchy for navigation. Using icCube you've two different ways :
1) You can use Categories to define at will a new hierarchy. Check documentation (categories-howto, categories-doc and categories-example ). Bear in mind that for the new hierarchy the parent / child relation is just visual and not data related (e.g. parent is the sum of his children)
2) You can define your navigation logic using the reporting tool. But this has his limitations in the current version 5.1 (most probably we will fix for 5.1.1)

Related

Calculated Members with multiple Attribute Hierarchy - MDX

I found this little code where it dynamically calculates TOTALs for all Dimension/Hierarchy I want.
This is close to what I need but will not work for Dimensions that have different number of Hierarchy Levels (Attribute Hierarchy). Current Code only works if there is only one Attribute Hierarchy because of CurrentMember.Parent. I could use CurrentMember.Parent.Parent for Dimension.Hierarchy that have two levels and so on but would not work for the the ones with only one Attribute Hierarchy (Level).
CALCULATE;
CREATE MEMBER CURRENTCUBE.[Measures].[Total On Hand Amount]
AS ([Measures].[On Hand Amount],Axis(1).Item(0).Item(0).Dimension.CurrentMember.Parent),
FORMAT_STRING = "#,#",
VISIBLE = 1 ;
I would like to make this MDX code work for any Dimension.Hierarchy regardless of number of Attribute Hierarchy (Level/s).
Any help is appreciated!!
You can use the ancestors function instead of parent. It takes a dimension parameter and a second parameter which shows how many levels you want to get (how deep in the tree to go). So if you know how many levels your dimension has you can use something like:
Ancestors(Axis(1).Item(0).Item(0).Dimension.CurrentMember, 5)
Instead of a number you can also add a dimension level as a second parameter. Then it will go as deep as the dimension level specified - so if you add the root dimension level it should get to there
(Axis(1).Item(0).Item(0).Dimension.Levels(0).Item(0), [Measures].[On Hand Amount])
Above gave me the correct answer, total for a measure for dynamic selection of any dimension but this MDX calculation would not work from PowerBI(DAX) report, which is merely PowerBI's limitation.
I got the TOTAL working now with this -
SCOPE(DESCENDANTS([Warehouses].[Warehouses],,AFTER));
[Measures].[Total On Hand Amount] = (ROOT([Warehouses]),[Measures].[On Hand Amount]);
END SCOPE;
I just have to repeat this SCOPE for each [Dimension].[Hierarchy] in the cube to make the TOTAL work for any selection including multiple dimensions from Power BI. It does not have dynamic functionality like Axis() did, but it yields the result I needed.
Hope this would help someone else too!!

MDX Dimension Navigation

I am on an MDX adventure and I'm at a point where I need to ask some questions.
I have a very basic dimension named Car. The attributes which comprise Car are as follows-
-Manufacturer
-Make
-Color
-Year
My fact table contains a sales measure ([Measures].[Sales]). I would like to know , without explicitly defining a user hierarchy, how to sum the sales from
a specific group in this hierarchy
For example, I want to sum the sales of all red Trucks made in 2002. My attempt errors out-
sum([Cars].[Make].[Make].&[Truck]&[Red]&[2002], [Measures].[Sales])
How can I navigate the attribute hierarchy in this way? I will be browsing the cube in excel
Thanks
If you open an mdx query in SSMS and drag a member from one of your attribute hierarchies into the query pain you will see the full name.
You definitely cannot chain hierarchies like this ...].&[Truck]&[Red]&[2002]
Each full name will likely be similar to what MrHappyHead has detailed but usually the attribute name is repeated e.g. for Make:
[Cars].[Make].[Make].&[Truck]
MrHappyHead have wrapped it all in the Sum function but this is not required - just wrap the coordinates in braces and a tuple is then formed which will point to the required area of the cube:
(
[Cars].[Make].[Make].&[Truck],
[Cars].[Color].[Color].&[Red],
[Cars].[Year].[Year].&[2002],
[Measures].[sales]
)
note: square brackets are pretty standard in mdx.
Is it something like:
Sum(
Cars.make.&[truck],
Cars.color.&[red],
Cars.year.[2002],
Measures.sales
)

How to get ascendants and descendants from level with parent-child hierarchy?

I have a location dimension with level, which have parent-child hierachy. In a fact table i have a location ID. I am need to take a ascendants or descendants of this item.
I found only this way, but it is bad, because i have to know all route to this item.
select {[Measures].[some measure]} ON COLUMNS,
Ascendants([location.location].[03D718E0039347C891237433E17F61E8].[281774B2C7A046F4B7AD5B2B921126D6]) ON ROWS
from [location]
I found an error. I use web apps for geting results with Tabular format, wich dont give me full information. Using Multidimensional format resolve this problem.

Parent-child dimension - confused levels

I am running Analysis Services 2008 R2 and have come across some behavior that I really do not understand and I can't seem to get to the bottom of it. I have a dimension called Segment which is a simple Parent-child dimension where only one of the four top-level members has any children. This one member, has two children. Only leaf nodes have any values.
In the dimension I have used AttributeAllMemberName to allow "All Segments" to be used to refer to the top-level members. There are three dimensions used in the cube: Segment, Country and Year.
When I run:
SELECT {{Descendants([Country].[Global],, SELF_BEFORE_AFTER)}} ON ROWS,
{[Segment].[All Segments].children}*{[Measures].[Volume tonnes]} ON COLUMNS
FROM [Market]
WHERE [Year].[2012]
I see all members on the columns but the one node that has children has an empty column. My understanding is that "children" should show me only one level not two. If, on the other hand I run
SELECT {{Descendants([Country].[Global],, SELF_BEFORE_AFTER)}} ON ROWS,
{[Segment].[(all)].[All Segments].children}*{[Measures].[Volume tonnes]} ON COLUMNS
FROM [Market]
WHERE [Year].[2012]
I see exactly what I would expect; the four top-level children with correctly aggregated values for the one child that has its own children. No grand-children are shown. In either case the right number of rows are displayed.
The only difference between the two queries is that the "[(all)]" level has been explicitly listed in the second query. Given that the "all" member is defined as the only member of the "(all)" level set, these two queries should return the same values but they don't. I must be missing something in the dimension config, but what? Can someone point me in the right direction to fix this? I need the query to work properly without having to use "[(all)]".
To stop this post becoming too bloated, I have posted some screen-grabs of BIDS to my own website to show the configuration of the dimension. There are three attributes and the dimension itself that require configuration but I can only post two links so have linked them all in from this page: http://coolwire.co.uk/share/BIDS.html
The Hierarchy and the Ordering are related to the Key by rigid attribute-relationships.
It all looks okay to me but the problem must be in here somewhere.

Is it possible to select 2 measures in different axis in MDX?

I have a question regarding MDX queries :
I have a SUBSCRIPTION cube about magazine subscriptions with two measures : NEW SUBS. and RETURNING SUBS.
I'm trying to make a query that displays both measures for two periods of time, and also the percentage growth in the period.
Example :
DESIRED VIEW - EXAMPLE
But I can't get this view using standard MDX, because I can't put measures in both axis.
The result I've got so far (not user friendly):
Using measure ON COLUMNS:
RESULT - NOT USER FRIENDLY
How can I do that first view using MDX formulas?
Thanks in advance.
Make growth a member of your time hierarchy like this:
WITH MEMBER [Time].[Calendar Date].[Growth] AS
[Time].[Calendar Date].[Jan-12] / [Time].[Calendar Date].[Jan-13] - 1
,format_string="0%"
SELECT { [Time].[Calendar Date].[Jan-12], [Time].[Calendar Date].[Jan-13], [Time].[Calendar Date].[Growth] }
ON COLUMNS,
{ Measures.NEW, Measures.RETURNING }
ON ROWS
FROM [SUBSCRIPTION]
I was guessing some names of your cube, you will have to adapt the MDX to your situation.
Calculated members need not be a member of the measures hierarchy, they can be used on every hierarchy of your cube. And to answer the question in the title of your question: No, one hierarchy can only be used in one axis in an MDX query.