dbTalk Databases Forums  

Re: Current Stock Value by Date

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


Discuss Re: Current Stock Value by Date in the microsoft.public.sqlserver.olap forum.



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

Default Re: Current Stock Value by Date - 02-17-2005 , 08:31 AM






As I said, it works fine in Custom Rollup Formula.

I tried to apply your calculation in Calc Measure:

iif(
IsLeaf( [DateDimension].CurrentMember),
CoalesceEmpty((Measures.[Value]) , (Measures.[Last Non Empty
Value],[DateDimension].PrevMember)),
([Measures].[Last Non Empty Value],
Tail(Descendants([DateDimension].CurrentMember,,LEAVES)).Item(0))
)

When CurrentMember is not leaf and hasn't any children it returns NULL. So,
I appended calculation with checking non-leaf member to hold NULL value:

iif(
IsLeaf( [DateDimension].CurrentMember),
CoalesceEmpty((Measures.[Value]) , (Measures.[Last Non Empty
Value],[DateDimension].PrevMember)),
CoalesceEmpty(([Measures].[Last Non Empty Value],
Tail(Descendants([DateDimension].CurrentMember,,LEAVES)).Item(0)),
([Measures].[Last Non Empty Value],
Tail(Descendants([DateDimension].CurrentMember.PrevMember,,LEAVES)).Item(0))
)
)

At that case, than non-leaf member hasn't any children i returns PrevMember
Value, but if PrevMember holds NULL value it also returns NULL. It means,
what recursion for non-leaf Members works only by one step back...


"Deepak Puri" <deepak_puri (AT) progressive (DOT) com> wrote

Quote:
Based on testing with the Foodmart Warehouse cube, this version of
Custom Rollup at 2nd level works:


Tail(NonEmptyCrossJoin(Descendants(
[DateDimension].CurrentMember,,LEAVES))).Item(0)



Another option is to modify [Last Non Empty Value]:


iif(IsLeaf([DateDimension].CurrentMember),
CoalesceEmpty((Measures.[Value]) ,
(Measures.[Last Non Empty Value],
[DateDimension].PrevMember)),
([Measures].[Last Non Empty Value], Tail(Descendants(
[DateDimension].CurrentMember,,LEAVES)).Item(0)))



- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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

Default Re: Current Stock Value by Date - 02-17-2005 , 10:58 AM






Can you give an example of "when CurrentMember is not leaf and hasn't
any children" - when a member has no children, shouldn't it be a leaf
member?


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
  #3  
Old   
gNM
 
Posts: n/a

Default Re: Current Stock Value by Date - 02-18-2005 , 01:54 AM



I mean it doesn't have children with data. For example there are no any
sales on January 1 and January 2 (Hours for these days contain NULL measure
values)

"Deepak Puri" <deepak_puri (AT) progressive (DOT) com> wrote

Quote:
Can you give an example of "when CurrentMember is not leaf and hasn't
any children" - when a member has no children, shouldn't it be a leaf
member?


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Reply With Quote
  #4  
Old   
deepak_puri@progressive.com
 
Posts: n/a

Default Re: Current Stock Value by Date - 02-19-2005 , 10:32 PM



Since I don't quite follow what's happening in your specific data,
here's a similar example for Foodmart Sales cube. Suppose that [Last
Sales] returns the last non-null [Unit Sales] at the leaf (month) Time
level. In this query, [1998].[Q1] is a non-leaf node with NULL [Unit
Sales]; but [Last Sales] returns the last non-null month's [Unit
Sales], which is 26,796:

Quote:
With member [Measures].[Last Sales] as
'iif(IsLeaf([Time].CurrentMember),
CoalesceEmpty(Measures.[Unit Sales] ,
(Measures.[Last Sales], [Time].PrevMember)),
([Measures].[Last Sales],
Tail(Descendants([Time].CurrentMember,,LEAVES)).Item(0)))'

select {[Unit Sales], [Last Sales]} on columns,
DrillDownLevel({[Time].[1997].[Q4],
[Time].[1998].[Q1]}) on rows
from Sales
Quote:

- Deepak



gNM wrote:
Quote:
I mean it doesn't have children with data. For example there are no
any
sales on January 1 and January 2 (Hours for these days contain NULL
measure
values)

"Deepak Puri" <deepak_puri (AT) progressive (DOT) com> wrote in message
news:uqcbuHRFFHA.464 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Can you give an example of "when CurrentMember is not leaf and
hasn't
any children" - when a member has no children, shouldn't it be a
leaf
member?


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


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.