dbTalk Databases Forums  

FirstChild and LastChild

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss FirstChild and LastChild in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paul
 
Posts: n/a

Default FirstChild and LastChild - 10-19-2005 , 09:51 AM






Hi,
Within a dimenion I need to find the first child at the leaf level. In
other words, if I have 5 levels and I'm at the top level my statement would
look something like this incredibly bad example...
[Time.Fiscal].FirstChild.FirstChild.FirstChild.FirstChild
would go down...
2005, QTR1, Jan, Week1, 1st giving me 01/01/2005 as the result

I Also Want the same thing but for LastChild
2005, QTR4, Dec, Week52, 31st giving me 31/12/2005as the result

How can I do this correctly and relatively simply.
Ta!
Paul

Reply With Quote
  #2  
Old   
Deepak Puri
 
Posts: n/a

Default Re: FirstChild and LastChild - 10-19-2005 , 02:03 PM






Hi Paul,

You could try Descendants() with the LEAVES option:

Descendants([Time.Fiscal].CurrentMember,,LEAVES).Item(0)

and

Tail(Descendants([Time.Fiscal].CurrentMember,,LEAVES)).Item(0)


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #3  
Old   
Denny Lee
 
Posts: n/a

Default Re: FirstChild and LastChild - 10-19-2005 , 05:48 PM



Here's an interesting way to do this:

with
member [Measures].[test] as '1'
select {
[Measures].[My Count]
} on columns, {
topcount(descendants([Domain].[Domain Hierarchy], 2, LEAVES), 1),
bottomcount(descendants([Domain].[Domain Hierarchy], 2, LEAVES), 1)
} on rows
from [Cube]

The trick for this is that:
Quote:
the descendants function will insure to get all of the members of the
dimension hierarchy. The two (2) is the number of levels you want to go
down; you'll want to specify what you want.

The problem with TopCount and BottomCount (because in this case you're
looking for the SQL equivalent of top and bottom against the dimension) is
that its based on a measure. So you'll notice the topcount and
bottomcount is applied against a measure I created ([Measures].[test])
which has a value of 1.

Since all of the values are 1, then the TopCount and BottomCount will
simply go with the internal hierarchy which then is the equivalent of
FirstChild.FirstChild and LastChild.LastChild in these cases respectively.
--
HTH!
Denny Lee
<dennyglee_at_hotmail_dot_com>
space: http://spaces.msn.com/members/denster/



"Paul" <Paul (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi,
Within a dimenion I need to find the first child at the leaf level. In
other words, if I have 5 levels and I'm at the top level my statement
would
look something like this incredibly bad example...
[Time.Fiscal].FirstChild.FirstChild.FirstChild.FirstChild
would go down...
2005, QTR1, Jan, Week1, 1st giving me 01/01/2005 as the result

I Also Want the same thing but for LastChild
2005, QTR4, Dec, Week52, 31st giving me 31/12/2005as the result

How can I do this correctly and relatively simply.
Ta!
Paul



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.