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

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.

Related

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 go from rows to a hierarchy in icCube

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)

Filter by dimension member only without sub-nodes

I need to query a cube by a ragged dimension (parent-child). The filter can be multiple nodes at any level.
This works in that it restricts the results to just the 2 supply chains I want...
SELECT [Measures].[Total Revenue] ON COLUMNS
, [Product].[Products].Members ON ROWS
FROM myCube
WHERE
(
{
[Supply Chain].[SupplyChains].&[{c0c62bda-0369-4591-be85-3a7078bc3352}]
, [Supply Chain].[SupplyChains].&[{aca836e9-22ac-4952-8809-3f50aeda6891}]
}
)
I know, guid keys, not my design! The problem is that data that isn't assigned to a specific supply chain is assigned to the top node. If I add the top node to the list, then all data will be returned (since all data is subordinate to it).
Is there a way to return values with a specific member and ignore its children? I'd like to say "return all data assigned exactly to the top node or to the listed supply chains and their children).
Thanks FrankPI, your comment pointed me in the right direction.
I ended up replicating the query in Excel and then examining the generated MDX using the OLAP PivotTable Extensions. Excel allows you to set filters on sub-nodes like what I was trying to do.
What it does is create a set of all nodes that don't have filtered sub-nodes to get everything else. Then for the parents of the nodes with filtered sub-nodes (and all its parents up to the root) it adds to the set those nodes but with the .DataMember function so that only the node value is included (but not its sub nodes). So basically instead of saying what NOT to get, it explicitly says what TO get, listing all other nodes which can be a bit cumbersome but works.

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.

How to get the name of invisible attributes and user defined Hierarchies using MDX?

I have a cube with some dimensions. There I have a dimension 'Product' which has some attributes and user defined hierarchies hidden. I do not know which attributes are hidden.
Is there a way to write an MDX to get the invisible attributes and user defined hierarchies?
I can get the name by other ways. But I want to know the way to get using MDX.
http://msdn.microsoft.com/en-us/library/ms145613.aspx gives an example query that reveals a member property:
WITH MEMBER [Measures].[Product List Price] AS
[Product].[Product].CurrentMember.Properties("List Price")
SELECT
[Measures].[Product List Price] on COLUMNS,
[Product].[Product].MEMBERS ON Rows
FROM [Adventure Works]
I cannot test it myself right now, but I assume that you could also write .Properties(0) or .Properties(1) to refer to properties by index, since you don't know the names. I'm not sure if there is a way to then discover the property name from the resulting cellset or not, sorry.
I'd start with looking into the DMVs for this, as you're really after metadata, not data.
http://dwbi1.wordpress.com/2010/01/01/ssas-dmv-dynamic-management-view/
They look like SQL, but run in the MDX window of SQL Management Studio, so will also run in an MSOLAP connection.
SELECT * FROM $system.mdschema_properties
That looks to be the query, a full list of members and a column identifying which are visible.
See how that works out for you.