Showing posts with label hierarchy. Show all posts
Showing posts with label hierarchy. Show all posts

Saturday, February 25, 2012

MDX Parent-Child Hierarchy ==> help

All,

I have a parent-child hierarchy and want to acheive the following through MDX in a single query

Filter for a member in parent-child hierarchy (any level ) - I can do that by using key Display the results at a fixed level (say Level 2, with 1 being the top level). The filter in the above point can be set from level 1 to level 5. Display always Level 1 and Level 2 in seperate columns in the report (with filters applied as specified in pt 1)

The foll query is in Adventure Works and says what I'm trying to acheive. 1. Filter for a member in parent-child, 2 & 3. Display Level 1 & 2 members. I know the below will not work but I have listed it to give an idea of what I'm trying to acheive.

Code Snippet

SELECT [Measures].[Amount] on 0

, {

[Organization].[Organizations].[Organization Level 01].Members,

[Organization].[Organizations].[Organization Level 02].Members

} on 1

FROM [Finance]

WHERE [Organization].[Organizations].&[6]

Please can someone help me with the query?

thanks...

Not knowing your application, it seems a little awkward to me, but if it meets your needs, go for it.

Still, one thing to consider is how a sub-select affects the cube space. The best way to explain this is to not and to simply show some data.

If you run your query above, you get a total of $12M for the North America. This is the North America total. However, is this what you really want? (Might be.)

In your sub-select, you attempt to limit on Organizations member with Key of 6. That is the Southeastern division member in Level 4 which has a total of only $216K. You can run the query below to see this.

By moving the criteria to the WHERE clause, we affect the values returned. Now, you can't obviously have the Organizations hierarchy in two places. But if you remember the leaf-level of this dimension is the Organization attribute hierarchy, you can reference the Southeastern division using that hierarchy.

So, the question is, are you wanting the $12M for North America or just wanting to see the Southeastern division's contribution of $216K?

Good luck,

Bryan

Code Snippet

WITH MEMBER Measures.OrgLvl1 AS

'[Organization].[Organizations].CurrentMember.Parent.Member_Value'

select

{Measures.OrgLvl1 ,[Measures].[Amount]} on 0,

[Organization].[Organizations].[Organization Level 02].Memberson 1

from Finance

WHERE [Organization].[Organization].&[6]

|||

Thanks Bryan. You are right. I need to use it in where clause using diff attribute.

Just noted one more thing. The parent value measure is diff in each of the above queries as the context of current member changes. I need the results of your corrected query with the parent as defined in my query (Parent should be AdventureWorks Cycle).

|||

Code Snippet

select

[Measures].[Amount] on 0,

EXISTS(

{

[Organization].[Organizations].[Organization Level 01].Members,

[Organization].[Organizations].[Organization Level 02].Members

},

[Organization].[Organizations].&[6]

)

on 1

from [Adventure Works]

|||

The problem is that I need the results in the following format. (one of the criteria that I had mentioned)

Col 1 (Org Level1 ) col 2 (Org Level 2) Measures.Amount

The above resultset filter for "[Organization].[Organizations].&[i/p]"

|||

I think I got it working using subqueries and calculated member. Pl advice if its not the way to do it or if there is a efficient way

Code Snippet

WITHMEMBER Measures.OrgLvl1 AS '[Organization].[Organizations].CurrentMember.Parent.Member_Value'

select {Measures.OrgLvl1 ,[Measures].[Amount]} on 0,

[Organization].[Organizations].[Organization Level 02].Memberson 1

from

(

Select [Organization].[Organizations].&[6] on 0

FROM [Finance])

Monday, February 20, 2012

MDX ORDER() QUESTION

Hello,

I'm trying to re-order my time hierarchy, from ascending to descending. When I use the following order statement, the years order descending, but the months remain ascending. How can I simply reverse the default order? Thanks.

(ORDER([Period Dim].[Calendar Hier].[Calendar Month].MEMBERS,[Period Dim].[Calendar Hier].CURRENTMEMBER.MEMBER_KEY,DESC)

results:

Calendar Year

Calendar Month

2006

"JANUARY 2006

2006

"FEBRUARY 2006

2005

"JANUARY 2005

2005

"FEBRUARY 2005

2005

"MARCH 2005

Try using MEMBER_VALUE instead of MEMBER_KEY. That seemed to work when I tried to reproduce using Adventure Works. See the query below.

HTH,

Dave Fackler

select

[Measures].[Internet Order Count] on columns,

Order([Date].[Calendar].[Month].Members, [Date].[Calendar].CurrentMember.Member_Value, bdesc) on rows

from

[Adventure Works]

|||

When I've reversed sets, I've found that method (MemberValue) to be VERY slow..
I just ran the query above and it was 33s.

This is 2s

select

[Measures].[Internet Order Count] on columns,

Order([Date].[Calendar].[Month].Members, [Date].[Calendar].CurrentMember.Properties ("ID", TYPED), bdesc) on rows

from

[Adventure Works]

MDX Multiselect and existing keyword usage

WITH

MEMBER LastYearSales
as
'
sum(
existing [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].MEMBERS,
(ParallelPeriod([Time].[Fiscal Calendar Hierarchy].[Fiscal Year]),
[TY Net Sales Amount])
)
'

MEMBER [Time].[Fiscal Calendar Hierarchy].[All Fiscal Periods].[ Grand Total]

AS 'AGGREGATE( EXISTING INTERSECT( { { EXTRACT( { [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010101],

[Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010102], [Time].[Fiscal Calendar Hierarchy].[Fiscal

Week].&[2006010103], [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010104] }, [Time].[Fiscal Calendar Hierarchy] ) }

}, { [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010101], [Time].[Fiscal Calendar Hierarchy].[Fiscal

Week].&[2006010102], [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010103], [Time].[Fiscal Calendar

Hierarchy].[Fiscal Week].&[2006010104] } ) )', SOLVE_ORDER = 1000

SELECT { LastYearSales } ON COLUMNS,

{ { [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010101], [Time].[Fiscal Calendar Hierarchy].[Fiscal

Week].&[2006010102], [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010103], [Time].[Fiscal Calendar

Hierarchy].[Fiscal Week].&[2006010104] }, ( [Time].[Fiscal Calendar Hierarchy].[All Fiscal Periods].[ Grand Total] ) } ON

ROWS

FROM [Sales]

CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL, ACTION_TYPE

========

OUTPUT

LastYearSales
Week 1 100
Week 2 200
Week 3 300
Week 4 400
Grand Total 50000 -> This is not the sum of the four weeks which should be 900. Instead it is sum across all weeks across all years in the time dimension. So effectively, the Existing statement is not getting the correct context (which is

the set of four fiscal weeks) while processing the aggregate (grand total) row. The only part of the code above that we can change is the definition of the calculated measure LastYearSales. The remaining is generated by proclarity.

We followed the recommendations by Mosha in his blog,
http://sqljunkies.com/WebLog/mosha/archive/2007/01/13/multiselect_parallelperiod.aspx

There is a problem with how Proclarity generates MDX in this case. (In fact I just reviewed very similar scenario this week). This is actually not multiselect scenario for which I wrote blog, but Visual Totals scenario, which is harder. The calculated member with Aggregate is not in the WHERE clause, therefore context for current coordinate is not set, and EXISTING in the definition of calculated member does nothing. Sorry, but the solution for multiselect won't work for Visual Totals.

MDX hierarchy problem

Hello,

My point is I wonder how to retrieve a leaf member from a date hierarchy.

I would like to retrieve the leaf of [Hierarchy Calendar] at the CurrentMember, which is a Date (as 2007/01/07).
[Hierarchy Calendar] is composed of : Year, Semester, Quarter, Month, Week of year, Date.

I can't retrieve the date of the hierarchy using [Date].[Hierarchy Calendar].[Date].CurrentMember, and I absolutly need to use a hierarchy, not the dimension : [DATE].[Date]

My final MDX must look like that:
IIF(IsEmpty(([Date].[Hierarchy Calendar].CurrentMember,[Measures].[NAV PER SHARE AMOUNT])),

NULL,

IIF(Not IsEmpty([Measures].[NAV PER SHARE AMOUNT]),[Measures].[PRODUCT FIRST NAV DATE] ,([Measures].[FIRST NAV DATE],[Date].[Hierarchy Calendar].[Date].CurrentMember.PrevMember)

)

)

Any help would be appreciated.

Thx,

Damien

Here are two queries that might help point you in the right direction.

Good luck,
Bryan

Code Snippet

with member [Measures].[x] as

SETTOSTR(DESCENDANTS([Date].[Calendar].CurrentMember,,LEAVES))

select

x on 0,

[Date].[Calendar].[Month].[October 2003] on 1

from [Adventure Works]

;

select

{} on 0,

EXISTS([Date].[Date].[Date].Members,[Date].[Calendar].[Month].[October 2003]) on 1

from [Adventure Works]

;

|||

I know the DESCENDANTS function but I think that's not the solution ...

Maybe another solution ? Wink

|||

How about that EXISTS function (in the second query)?

B.

|||

Thanks for your help.

For information, I resolved my problem with this, it's not very optimized but works under my scheduling constraints Smile

Thanks again.

.FIRSTCHILD:[DATE].[Hierarchy Calendar].CURRENTMEMBER,NOT ISEMPTY([Measures].[NAV PER SHARE AMOUNT])),EXCLUDEEMPTY) =0,

([MEASURES].[FIRST NAV DATE],[DATE].[Hierarchy Calendar].CurrentMember.Parent.Parent.PrevMember),

([DATE].[Hierarchy Calendar].CurrentMember.Parent.Parent,[Measures].[PRODUCT FIRST NAV DATE])

)

)

),

IIF(ISEMPTY(([Measures].[NAV PER SHARE AMOUNT])),

IIF([DATE].[Hierarchy Calendar].CurrentMember.Level IS [DATE].[Hierarchy Calendar].[Year] OR COUNT(filter([DATE].[Hierarchy Calendar].CurrentMember.Parent.FirstChild:[DATE].[Hierarchy Calendar].CurrentMember,not isempty([Measures].[NAV PER SHARE AMOUNT])))>0,

([Measures].[FIRST NAV DATE],[DATE].[Hierarchy Calendar].CurrentMember.PrevMember),

([Measures].[FIRST NAV DATE],[DATE].[Hierarchy Calendar].CurrentMember.Parent.PrevMember)

),

[Measures].[PRODUCT FIRST NAV DATE]

)

)

)

MDX hierarchy problem

Hello,

My point is I wonder how to retrieve a leaf member from a date hierarchy.

I would like to retrieve the leaf of [Hierarchy Calendar] at the CurrentMember, which is a Date (as 2007/01/07).
[Hierarchy Calendar] is composed of : Year, Semester, Quarter, Month, Week of year, Date.

I can't retrieve the date of the hierarchy using [Date].[Hierarchy Calendar].[Date].CurrentMember, and I absolutly need to use a hierarchy, not the dimension : [DATE].[Date]

My final MDX must look like that:
IIF(IsEmpty(([Date].[Hierarchy Calendar].CurrentMember,[Measures].[NAV PER SHARE AMOUNT])),

NULL,

IIF(Not IsEmpty([Measures].[NAV PER SHARE AMOUNT]),[Measures].[PRODUCT FIRST NAV DATE] ,([Measures].[FIRST NAV DATE],[Date].[Hierarchy Calendar].[Date].CurrentMember.PrevMember)

)

)

Any help would be appreciated.

Thx,

Damien

Here are two queries that might help point you in the right direction.

Good luck,
Bryan

Code Snippet

withmember [Measures].[x] as

SETTOSTR(DESCENDANTS([Date].[Calendar].CurrentMember,,LEAVES))

select

x on 0,

[Date].[Calendar].[Month].[October 2003] on 1

from [Adventure Works]

;

select

{} on 0,

EXISTS([Date].[Date].[Date].Members,[Date].[Calendar].[Month].[October 2003]) on 1

from [Adventure Works]

;

|||

I know the DESCENDANTS function but I think that's not the solution ...

Maybe another solution ? Wink

|||

How about that EXISTS function (in the second query)?

B.

|||

Thanks for your help.

For information, I resolved my problem with this, it's not very optimized but works under my scheduling constraints Smile

Thanks again.

.FIRSTCHILD:[DATE].[Hierarchy Calendar].CURRENTMEMBER,NOTISEMPTY([Measures].[NAV PER SHARE AMOUNT])),EXCLUDEEMPTY) =0,

([MEASURES].[FIRST NAV DATE],[DATE].[Hierarchy Calendar].CurrentMember.Parent.Parent.PrevMember),

([DATE].[Hierarchy Calendar].CurrentMember.Parent.Parent,[Measures].[PRODUCT FIRST NAV DATE])

)

)

),

IIF(ISEMPTY(([Measures].[NAV PER SHARE AMOUNT])),

IIF([DATE].[Hierarchy Calendar].CurrentMember.LevelIS [DATE].[Hierarchy Calendar].[Year] ORCOUNT(filter([DATE].[Hierarchy Calendar].CurrentMember.Parent.FirstChild:[DATE].[Hierarchy Calendar].CurrentMember,notisempty([Measures].[NAV PER SHARE AMOUNT])))>0,

([Measures].[FIRST NAV DATE],[DATE].[Hierarchy Calendar].CurrentMember.PrevMember),

([Measures].[FIRST NAV DATE],[DATE].[Hierarchy Calendar].CurrentMember.Parent.PrevMember)

),

[Measures].[PRODUCT FIRST NAV DATE]

)

)

)

MDX Hierarchy help

I have two calendar hierarchies in a 2005 SSAS cube. I have to make some calculations based on the date level, but of course, my calculated measures dont work when the wrong hierarchy is chosen.

I have tried to look at the .hierarchy and hierarchy() function but am unable to really understand how they work and I haven't been terribly successful looking online for info on them.

Has anyone had a similar issue? How did you test for the current hierarchy?

Here's an Adventure Works example, when either the Calendar or Fiscal hierarchy is selected on rows:

>>

With Member [Measures].[DateHierarchy] as

Axis(1).Item(0).Item(0).Hierarchy.Name

select {[Measures].[Order Quantity],

[Measures].[DateHierarchy]} on 0,

Non Empty [Date].[Calendar].[Calendar Year] on 1

from [Adventure Works]

-

Order Quantity DateHierarchy
CY 2001 11,848 Calendar
CY 2002 60,918 Calendar
CY 2003 124,615 Calendar
CY 2004 77,395 Calendar

>>

Another approach is to test whether the current member of each hierarchy is the default member (assuming that only 1 hierarchy has been navigated).