dbTalk Databases Forums  

Calculated member for dynamically computing opening balance

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


Discuss Calculated member for dynamically computing opening balance in the microsoft.public.sqlserver.olap forum.



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

Default Calculated member for dynamically computing opening balance - 05-02-2006 , 05:20 PM






Fact: Census
-------------
- Census count (values 1 or 0)
- CalendarKey (dates in the format "yyyymmdd")

Dimension: Calendar
----------------------
- CalendarKey(dates in the format "yyyymmdd")


How do I get a calculated member "OpeningBal" (in psuedocode)
"Opening Balance = Sum(Census Count - where Calendarkey <= user entered date
)?"

I tried creating a Named Set called "CalendarDates" but could not use it to
get the dates <= user entered dates.

Any help is greatly appreciated.
--
Thank you,
Ashok G

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

Default Re: Calculated member for dynamically computing opening balance - 05-02-2006 , 08:21 PM






Assuming AS 2000, a cube measure: [CensusCount], and user selection of a
date on the Calendar dimension, the MDX for the calculated measure:
[OpeningBal] could be like:

Sum(PeriodsToDate([Calendar].[(All)]),
[Measures].[CensusCount])



- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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

Reply With Quote
  #3  
Old   
Ashok G
 
Posts: n/a

Default Re: Calculated member for dynamically computing opening balance - 05-03-2006 , 07:49 AM



Thank you for your prompt response. The PeriodsToDate() function returns the
sum(Census count) only upto a partilular [Month] level in the Calendar
dimension. I provided the level as
SUM(PeriodsToDate([Calendar].[Calendars].[(All)]), [Measures].[CensusCount])
Any thoughts why it would not work for a specific [Date]?

Below is my calendar dimension attributes:
- Group (values "Calendar" or "Fiscal")
- Year (1978, 1979, ....)
- Quarter (1,2,3,4)
- Month (1,2,3,4..12)
- Week number (1,2,3,....)
- Date (yyyymmdd values---displays alternate attribute in format "April 1,
2006")

The above attributes are also part of a user heirarchy ("Calendars") as
Group->Year->Quarter->Month->Week number->Date.

Thanks you so much for your help. As always I really appreciate it.

--
Thank you,
Ashok G


"Deepak Puri" wrote:

Quote:
Assuming AS 2000, a cube measure: [CensusCount], and user selection of a
date on the Calendar dimension, the MDX for the calculated measure:
[OpeningBal] could be like:

Sum(PeriodsToDate([Calendar].[(All)]),
[Measures].[CensusCount])



- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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


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

Default Re: Calculated member for dynamically computing opening balance - 05-03-2006 , 10:08 AM



Since it sounds like you're using AS 2005, you might try explicitly
specifying the Hierarchy current member, like:

Sum(PeriodsToDate([Calendar].[Calendars].[(All)],
[Calendar].[Calendars].CurrentMember),
[Measures].[CensusCount])

(assuming that the date is selected on this hierarchy).


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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

Reply With Quote
  #5  
Old   
Ashok G
 
Posts: n/a

Default Re: Calculated member for dynamically computing opening balance - 05-03-2006 , 10:30 AM



Deepak,

Yes I am using AS2005.
Tried as you suggested and I explicitly declared the heirarchy and used the
heirarchy in the Dimension filter expression. I am able to get some results
only as long as I navigate and select upto the [Month] level in the heirarchy
(heirarchy is Group->Year->Quarter->Month->Week number->Date). The results
become 0 as soon as a enter a value for either the [Week number] level or the
[Date] level. Strange huh!

I have verified that the data exists in the underlying table for the filter
condition for the [Date] so I am at a loss as to why it does not return any
values after [Month].

Can you please help?


--
Thank you,
Ashok G


"Deepak Puri" wrote:

Quote:
Since it sounds like you're using AS 2005, you might try explicitly
specifying the Hierarchy current member, like:

Sum(PeriodsToDate([Calendar].[Calendars].[(All)],
[Calendar].[Calendars].CurrentMember),
[Measures].[CensusCount])

(assuming that the date is selected on this hierarchy).


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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


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

Default Re: Calculated member for dynamically computing opening balance - 05-03-2006 , 11:43 AM



Ashok,

It's hard to say without looking at the Attribute Relationships in your
[Calendar] dimension, but I suspect that there may be an issue with the
modelling of weeks. Unless you're using an accounting calendar, weeks
don't roll up exactly to months - they may span 2 months. Will it work
down to the day level, if you remove weeks from the Calendar hierarchy?


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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

Reply With Quote
  #7  
Old   
Ashok G
 
Posts: n/a

Default Re: Calculated member for dynamically computing opening balance - 05-09-2006 , 10:58 AM



Hi Deepak,

I finally figured out the issue. There were a couple places where I was
headed in the wrong direction. Basically I was placing the filter condition
in the SubCube filter area of the BI studio. Also I used the PeriodsToDate()
as follows:

SUM(PeriodsToDate([Calendar].[Calendars].[Group], [Measures].[CensusCount])

That did the trick.

Thanks for helping me though clarify my thoughts and understanding


--
Thank you,
Ashok G


"Deepak Puri" wrote:

Quote:
Ashok,

It's hard to say without looking at the Attribute Relationships in your
[Calendar] dimension, but I suspect that there may be an issue with the
modelling of weeks. Unless you're using an accounting calendar, weeks
don't roll up exactly to months - they may span 2 months. Will it work
down to the day level, if you remove weeks from the Calendar hierarchy?


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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


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.