dbTalk Databases Forums  

Leap Years

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


Discuss Leap Years in the microsoft.public.sqlserver.olap forum.



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

Default Leap Years - 01-19-2006 , 09:36 AM






Can anyone tell me a good way to identify a leap year for my time dimension
in a calculated measure. A mod functions would work, but MDX does not
support the mod function. I did an iif() statement similar to this:

iif([Time].[Dimension].[level].[name] = '2004', 364, 365)

I'm looking for an absolute solution, not just looking isolating 2004.

Thanks for the help!

Reply With Quote
  #2  
Old   
Vladimir Chtepa
 
Posts: n/a

Default Re: Leap Years - 01-19-2006 , 12:08 PM






Hi,

I would be count the days dimension members, or if it is too expansive, i
would be create property - days_count.

Vladimir Chtepa

"Scott Mescall" <ScottMescall (AT) discussions (DOT) microsoft.com> schrieb im
Newsbeitrag newsC027330-C682-497B-BD93-E7D5573CF79A (AT) microsoft (DOT) com...
Quote:
Can anyone tell me a good way to identify a leap year for my time
dimension
in a calculated measure. A mod functions would work, but MDX does not
support the mod function. I did an iif() statement similar to this:

iif([Time].[Dimension].[level].[name] = '2004', 364, 365)

I'm looking for an absolute solution, not just looking isolating 2004.

Thanks for the help!



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

Default Re: Leap Years - 01-19-2006 , 07:28 PM



Here's a VBA version - may not be the most efficient:

Quote:
With Member [Measures].[IsLeapYear] as
'Day(DateSerial(CInt(Ancestor([Time].CurrentMember,
[Time].[Year]).Name), 2, 28) + 1) = 29'

Select {[Measures].[IsLeapYear]} on 0,
[Time].[Month].Members on 1
from Sales
Quote:

This is based on the VBA Developer's Handbook Chapter 2: Working with
Dates and Times:

http://msdn.microsoft.com/library/de.../en-us/dnvbade
v/html/isthisleapyear.asp
Quote:
...
Yes, you could write the code to handle this yourself, and it's not all
that difficult. But why do it? VBA is already handling the algorithm
internally. It knows that the day after February 28 (in all but a leap
year) is March 1 but in a leap year it's February 29. To take advantage
of this fact, dhIsLeapYear (shown in Listing 2.16) calculates the answer
for you.
...
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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


Reply With Quote
  #4  
Old   
Jimmy
 
Posts: n/a

Default Re: Leap Years - 01-30-2006 , 12:04 PM



Doesn't a leap year happen every 4 years?

Example against Foodmart 2000:

With Member [Measures].[IsLeapYear] as
'IIF(Int(Time.CurrentMember.Properties("Caption")) / 4 -
Int(Int(Time.CurrentMember.Properties("Caption")) / 4) = 0, 1, 0)'

Select {[IsLeapYear]} on 0, [Time].[Year].Members on 1 from [Sales]

"Scott Mescall" <ScottMescall (AT) discussions (DOT) microsoft.com> wrote

Quote:
Can anyone tell me a good way to identify a leap year for my time
dimension
in a calculated measure. A mod functions would work, but MDX does not
support the mod function. I did an iif() statement similar to this:

iif([Time].[Dimension].[level].[name] = '2004', 364, 365)

I'm looking for an absolute solution, not just looking isolating 2004.

Thanks for the help!



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

Default Re: Leap Years - 01-30-2006 , 05:20 PM



That'll work - for a few generations - till 2100!

http://en.wikipedia.org/wiki/Leap_year
Quote:
...
The Gregorian calendar, the current standard calendar in most of the
world, adds a 29th day to February in all years evenly divisible by 4,
except for century years (those ending in -00), which receive the extra
day only if they are evenly divisible by 400. Thus 1996 was a leap year
whereas 1999 was not, and 1600, 2000 and 2400 are leap years but 1700,
1800, 1900 and 2100 are not.
...
Quote:

- 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.