3

We have a cube called Revenue.

SELECT
    {[Measures].[Billable Hours]} on columns,
     [Period].[Financial Year].**[Financial Year]** on rows
FROM [REVENUE];

SELECT 
    {[Measures].[Billable Hours]} on columns,
     [Period].[Financial Year].**Children** on rows
FROM [REVENUE];

There is a dimension "Period", with I guess the attribute hierarchy is Financial Year? and if I want rows like 2012, 2013, 2014, I have to say either [Period].[Financial Year].Children or [Period].[Financial Year].[Financial Year]. To get [Period].[Financial Year].[Financial Year], in SSMS, I opened that attribute hierarchy, dragged the little dot under Members that says Financial Year, and that's what it gave me.

Both ways get me the same result. So just wondering,

  1. is .Children more preferable, or is it just preference?

  2. Also, if one were to "diagram" [Period].[Financial Year].[Financial Year], would it be "Dimension.Level.Member"? so is [Financial Year]/Children a member, or how does one diagram that "whole thing" and

  3. what should I call that whole thing?
whytheq
  • 34,466
  • 65
  • 172
  • 267
John
  • 98
  • 5

2 Answers2

3

Unsure what you mean by "diagram".

Both of you column expressions are, I think, short-cuts.

This

[Period].[Financial Year].[Financial Year]

Is short for this

[Period].[Financial Year].[Financial Year].MEMBERS

And this:

[Period].[Financial Year].CHILDREN

Is short for this:

[Period].[Financial Year].[All].CHILDREN

(To rewind a bit)

All attribute hierarchies have two levels - an all level and a leaf level. The all level only has a single member [All] which in turn has members - the leaves. There is also the leaf level, made up of the leaves.

So it looks like you've tapped into these two different levels of the hierarchy [Financial Year].


Which should you use? Sometimes I don't believe it matters. In more complex scenarios maybe which you use will have an impact on performance.

Sometimes you might like to grab the All member and the leaves - then you can do something like the following:

SELECT 
    {[Measures].[Billable Hours]} on columns,
     [Period].[Financial Year].MEMBERS on rows
FROM [REVENUE]; 

This should return a set that includes the All member?


Q2

This [Period].[Financial Year].[Financial Year] is Dimension.Hierarchy.Level. The hierarchy's All member is not accessible at this level.


To repeat Greg Galloway's comment:

[Period].[Financial Year].CHILDREN assumes the All member is the default member and the current member in the context and won't work as intended in all contexts.

Preferable to use [Period].[Financial Year].[All].CHILDREN or [Period].[Financial Year].[Financial Year].MEMBERS

whytheq
  • 34,466
  • 65
  • 172
  • 267
  • I prefer [Period].[Financial Year].[Financial Year].MEMBERS as I think it is most unambiguous. I believe [Period].[Financial Year].CHILDREN assumes the All member is the default member and the current coordinate so your mileage may vary. But I agree I see that a lot. – GregGalloway Aug 18 '15 at 01:27
  • I'm reading MDX Step by Step, ran to page 74, and it explained "in an attribute hierarchy, **the leaf level of the hierarchy is named the same as the attribute-hierarchy itself**". That is exactly what I wanted to know, but thanks for your answer as well. – John Aug 18 '15 at 02:28
  • I was also confusing myself, thinking "dimension.level.member", and not recognizing that attribute hierarchies were also hierarchies like user defined hierarchies, but now that I see they are the same, "Dimension.Hierarchy.Level", and using the attribute hierarchy twice to get leaves is what I was confused at [Period].**[Financial Year].[Financial Year]** but now I understand – John Aug 18 '15 at 02:30
  • @GregGalloway would you like me to edit this answer at all? 100% happy to change anything in this answer you feel I should change - I'm just a learner. p.s. would be great to see you on `mdx` questions more often sir - this forum is great to use (a lot better technology than MS's SSAS forum) but lacks some real `mdx` expert contributors like yourself. There used to be a good `mdx` overseer `FrankPI` but I think he got fed up of the lack of activity, or triviality of many of the questions, and left. – whytheq Aug 18 '15 at 06:35
  • @whytheq thanks. Trying to help moderate. I would recommend you edit your answer and mention [Period].[Financial Year].CHILDREN assumes the All member is the default member and the current member in the context and won't work as intended in all contexts. Prefer [Period].[Financial Year].[All].CHILDREN or [Period].[Financial Year].[Financial Year].MEMBERS – GregGalloway Aug 18 '15 at 12:32
  • @whytheq - He was FrankPl (l as in lemon) :P Greg - good to have you here! This tag is rarely visited by experts like you unlike the other popular tags. – SouravA Aug 19 '15 at 13:08
2

John, I have been in a similar situation before and had posted a question on SO on that.

The point is that it is not just a shortcut, but a risky practice to write [Dim].[Attribute].CHILDREN, since the [All] member, which the other answer talks about is a scoped member and it can't always be assumed that you are actually writing [Dim].[Attribute].[All].CHILDREN unless you write that additional [All]. Best to avoid it.

Also, the [Period].[Financial Year].[Financial Year] is not really a suggested way of invoking members.

The moral of the story is we definitely should try to not fall for any "shortcuts".

EDIT: Why it is imperative to be explicit!

The reason why .MEMBERS is the "suggested" way is because the SSAS engine does an additional check when you use the .MEMBERS function.

If a newbie MDX coder accidentally use a nonexistent hierarchy name(typo..uses Calendar1 instead of Calendar, the engine surprisingly doesn't throw any error. (Pardon me for the white gaps below the following images)

enter image description here

But if .MEMBERS is used, an extra layer of checking takes place, which gives a clear and definitive error message:

enter image description here

Obviously, here the engine is to blame, probably this is a bug. But, we must do our part at using the tools at hand. In a similar way, 9 out of 10 times, Dim.Hier.CHILDREN syntax will work, but the fact is, it is misleading. A newbie might look at the code and assume that a hierarchy can have children. While the truth is only a member can have children.

Little off topic, but in SQL too, it is a standard ANSI syntax to use a semicolon at the end of a statement, but very few people actually use that syntax. The engine in turn punishes us by throwing error when semicolons are not used with some operators, like when we use CTE. SO should we make it a habit to use more semicolons? Hell yeah! Is it a really a shortcut? No!

Community
  • 1
  • 1
SouravA
  • 5,147
  • 2
  • 24
  • 49
  • Hello Sourav - this statement isn't correct `Also, the [Period].[Financial Year].[Financial Year] is not really a suggested way of invoking members.`. This shortcut was designed as part of the language. See this post by Mosha to see it in use: http://sqlblog.com/blogs/mosha/archive/2008/10/24/optimizing-order-of-sets-in-mdx-crossjoins.aspx – whytheq Aug 18 '15 at 09:32
  • 1
    @whytheq - Edited my answer and added some content. It's more of a best practice thing. – SouravA Aug 18 '15 at 11:04
  • What is a scoped member? Having trouble finding a definition on Google. It makes sense that only a member can have children, and not a hierarchy... But besides being "misleading" or not throwing errors, is there ever a situation where Dim.Hier.Children would return different results than Dim.Hier.All.Children? I'm just using the methodology I get when I drag fields from SSMS MDX – John Aug 18 '15 at 13:11
  • Did you see the example I mentioned in my question? If not, here it is : http://stackoverflow.com/questions/25786590/difference-in-results-while-using-children-and-allmembers-in-an-mdx-statement – SouravA Aug 18 '15 at 13:19
  • What I mean is that `[All]` is not really a member. It is a calculated aggregate whose definition changes based on the members within scope(which is set by slicer or the subcube). In the example I quoted, I was using a subcube. – SouravA Aug 18 '15 at 13:22
  • I don't think there would ever be a scenario where not using `All` in your query would yield different results. But after I learnt my lesson, I desist from using `.CHILDREN` on hierarchy. – SouravA Aug 18 '15 at 13:29
  • @SouravA `[All]` is 100% a member - whereas `[(All)]` is a level. You say wrongly that `..[All] is not really a member`. Also you need to add in the magical semi-colon to your screen-prints. – whytheq Aug 18 '15 at 19:59
  • @john as mentioned in the comment made above by Greg Galloway - if you leave out `[All]` then you will get whatever is the default member of the hierarchy - so effectively you are getting this `[Dim].[Hier].[].CHILDREN`. In most contexts this default member is `[All]` but sometimes it may not be and then you get unexpected results. – whytheq Aug 18 '15 at 20:03
  • Very helpful. I will be conscious of the default member:) – John Aug 19 '15 at 00:06
  • [All] is not really a *real* member. Sounds better? As per MSDN, * All member. It is a system-generated member that is not contained in the dimension table. Because the member in the (All) level is at the top of the hierarchy, the member's value is the consolidated aggregation of the values of all members in the hierarchy. The All member often serves as the default member of a hierarchy.* More on the [All] member here: http://www.bp-msbi.com/2010/02/all-member-properties-name-key-and/ – SouravA Aug 19 '15 at 03:42
  • @whytheq - The semicolon is not part of MDX syntax requirements, unless you are talking about the "calculations" tab in cube designer. – SouravA Aug 19 '15 at 03:53
  • @SouravA I use semi-colon after all mdx and sql statements – whytheq Aug 19 '15 at 08:06
  • I know. I am a fan of how neat your code looks like. Looks like a good habit you picked up from your .NET background. But don't you agree with me that there are no situations where it would cause errors(in SSMS)? – SouravA Aug 19 '15 at 08:08
  • 1
    @SouravA I agree - I was just joking with you as I found it amusing that you'd stressed the use of semi-colons (sql) but in the screen-prints (mdx) there were none. I understand there is a difference (cte) but just thought it was funny. – whytheq Aug 19 '15 at 13:17