dbTalk Databases Forums  

obtaining current month from system date using MDX

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


Discuss obtaining current month from system date using MDX in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jared Smith via SQLMonster.com
 
Posts: n/a

Default obtaining current month from system date using MDX - 11-09-2004 , 08:16 PM






Hi there,

I am using the following MDX to default to the current month.

tail(filter([FiscalYear].[Month].members, not
isempty([FiscalYear].currentmember)),1).item(0)


The issue i have however, is if there is an incorrect transaction in the system for a date in the future, or of there is budget data, this MDX will not work. How can I use MDX to somehow point to the Current month from the System date?

Is there a way to do this?

e.g. Where system month = dimension time period

*****************************************
* This message was posted via http://www.sqlmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse....e9dbd7cbd61333
*****************************************

Reply With Quote
  #2  
Old   
Neo
 
Posts: n/a

Default Re: obtaining current month from system date using MDX - 11-09-2004 , 09:30 PM






Hi,
I think u can use month(now())as a calculated member to get the current
month.

Neo

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

Reply With Quote
  #3  
Old   
Steve McHugh
 
Posts: n/a

Default Re: obtaining current month from system date using MDX - 11-10-2004 , 03:54 AM



A combination of StrToMember and calling "VBA!CStr(Month(Now()))" may
help you out.

Steve


Reply With Quote
  #4  
Old   
Jared Smith via SQLMonster.com
 
Posts: n/a

Default Re: obtaining current month from system date using MDX - 11-10-2004 , 12:58 PM



Thanks Neo...I have tried using this function, however it returns an integer as in 11 for November...I need to be able to match this to a member in my Dimension....i.e. November 2004

*****************************************
* A copy of the whole thread can be found at:
* http://www.sqlmonster.com/Uwe/Forum....rver-olap/4563
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse....a79a840135c2b0
*****************************************

Reply With Quote
  #5  
Old   
Jared Smith via SQLMonster.com
 
Posts: n/a

Default Re: obtaining current month from system date using MDX - 11-10-2004 , 01:02 PM



I have tried using it as:

StrToMember(VBA!CStr(Month(Now())))

But it errors...sorry but my MDX is far from good.

*****************************************
* A copy of the whole thread can be found at:
* http://www.sqlmonster.com/Uwe/Forum....rver-olap/4563
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse....bb4aa05f8db0bf
*****************************************

Reply With Quote
  #6  
Old   
Jared Smith via SQLMonster.com
 
Posts: n/a

Default Re: obtaining current month from system date using MDX - 11-10-2004 , 01:02 PM



I have tried using it as:

StrToMember(VBA!CStr(Month(Now())))

But it errors...sorry but my MDX is far from good.

*****************************************
* A copy of the whole thread can be found at:
* http://www.sqlmonster.com/Uwe/Forum....rver-olap/4563
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse....e85e512f4629d3
*****************************************

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

Default Re: obtaining current month from system date using MDX - 11-10-2004 , 04:20 PM



The exact syntax depends on the structure of your date dimension. Here's
a working example for the Foodmart Sales cube. It selects the current
calendar month (11), but subtracts 7 from the current year, to select
1997 data:

Quote:
select {[Measures].[Unit Sales]} on columns,
{StrToMember("[Time].["
+ CStr(Year(Now())-7) + "].[Q"
+ CStr(CInt((Month(Now())-1)/3)+1) + "].["
+ CStr(Month(Now())) + "]")} on rows
from Sales
Quote:

- Deepak

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


Reply With Quote
  #8  
Old   
Jared Smith via SQLMonster.com
 
Posts: n/a

Default Re: obtaining current month from system date using MDX - 11-10-2004 , 09:26 PM



Is this code used in a calculated member?

*****************************************
* A copy of the whole thread can be found at:
* http://www.sqlmonster.com/Uwe/Forum....rver-olap/4563
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse....c72ccd5f5e97f1
*****************************************

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

Default Re: obtaining current month from system date using MDX - 11-10-2004 , 09:50 PM



This is an MDX query, which can be run in the MDX Sample App that is
installed with Analysis Manager. But the StrToMember() section can
certainly be used elsewhere.


- Deepak

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

Reply With Quote
  #10  
Old   
Prasanna
 
Posts: n/a

Default Re: obtaining current month from system date using MDX - 11-16-2004 , 04:40 AM



Hi Smith,
try the MDX below

strtomember("Time.[" + IIf(Month(Now()) = 1,
LTrim(RTrim(Str(Year(Now()) - 1))), LTrim(RTrim(Str(Year(Now()))))) +
"].&[" + IIf(Month(Now()) = 1, LTrim(RTrim(Str(12))),
LTrim(RTrim(Str(Month(Now()) - 1)))) + "]")

the above MDX would give you previous month from the current month
which you can change according to your need

Regards
Prasanna

"Jared Smith via SQLMonster.com" <forum (AT) SQLMonster (DOT) com> wrote

Quote:
I have tried using it as:

StrToMember(VBA!CStr(Month(Now())))

But it errors...sorry but my MDX is far from good.

*****************************************
* A copy of the whole thread can be found at:
* http://www.sqlmonster.com/Uwe/Forum....rver-olap/4563
*
* Report spam or abuse by clicking the following URL:
* http://www.sqlmonster.com/Uwe/Abuse....bb4aa05f8db0bf
*****************************************

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.