dbTalk Databases Forums  

Need to use variable for year

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


Discuss Need to use variable for year in the microsoft.public.sqlserver.olap forum.



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

Default Need to use variable for year - 08-31-2004 , 05:21 PM






I'm going crazy. The MDX query below gives me all the months and
their corresponding sales for a two-year period, which is what I want.
However, I have no idea how to substitute the hard-coded year values
with the current year for [2004] and the prior year for [2003]. Is
there some kind of variable I can use to set "CurrentYear =
Year(Current_Timestamp)" and "PriorYear = Year(Current_Timestamp) -1"
or something?

I need to build a report with Reporting Services that will display
this data. If I leave the hard-coded dates, the report will be
invalid next year, which is why the current and prior years need to be
variables rather than hard-coded values.

My TimeDimension levels are set up as Year, Quarter, Month, and Day.

SELECT { [Measures].[Amt Sold], [Measures].[Num Sold] } ON COLUMNS,
{YTD([TimeDimension].[2003].[Quarter
4].[December]),YTD([TimeDimension].[2004].[Quarter 4].[December]) }
DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS
FROM [Sales]

Reply With Quote
  #2  
Old   
Abhinav Kumar
 
Posts: n/a

Default Need to use variable for year - 08-31-2004 , 07:30 PM






MDX in Analysis Server 2000 does not support parameters
but you can do this programmatically by generating the
MDX dynamically.

Abhinav Kumar
akumar (AT) itmag (DOT) com.au

Quote:
-----Original Message-----
I'm going crazy. The MDX query below gives me all the
months and
their corresponding sales for a two-year period, which
is what I want.
However, I have no idea how to substitute the hard-
coded year values
with the current year for [2004] and the prior year for
[2003]. Is
there some kind of variable I can use to
set "CurrentYear =
Year(Current_Timestamp)" and "PriorYear = Year
(Current_Timestamp) -1"
or something?

I need to build a report with Reporting Services that
will display
this data. If I leave the hard-coded dates, the report
will be
invalid next year, which is why the current and prior
years need to be
variables rather than hard-coded values.

My TimeDimension levels are set up as Year, Quarter,
Month, and Day.

SELECT { [Measures].[Amt Sold], [Measures].[Num Sold] }
ON COLUMNS,
{YTD([TimeDimension].[2003].[Quarter
4].[December]),YTD([TimeDimension].[2004].[Quarter 4].
[December]) }
DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS
FROM [Sales]
.


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

Default Re: Need to use variable for year - 09-01-2004 , 10:02 AM



Using Reporting Services you'll have to set up parameters for your time
periods you want. Use these parameter values in your dynamic MDX statement.

You can also write some custom code to get the current year and from that
the previous year also. See vb.net date functions.


"Abhinav Kumar" <akumar (AT) itmag (DOT) com.au> wrote

Quote:
MDX in Analysis Server 2000 does not support parameters
but you can do this programmatically by generating the
MDX dynamically.

Abhinav Kumar
akumar (AT) itmag (DOT) com.au

-----Original Message-----
I'm going crazy. The MDX query below gives me all the
months and
their corresponding sales for a two-year period, which
is what I want.
However, I have no idea how to substitute the hard-
coded year values
with the current year for [2004] and the prior year for
[2003]. Is
there some kind of variable I can use to
set "CurrentYear =
Year(Current_Timestamp)" and "PriorYear = Year
(Current_Timestamp) -1"
or something?

I need to build a report with Reporting Services that
will display
this data. If I leave the hard-coded dates, the report
will be
invalid next year, which is why the current and prior
years need to be
variables rather than hard-coded values.

My TimeDimension levels are set up as Year, Quarter,
Month, and Day.

SELECT { [Measures].[Amt Sold], [Measures].[Num Sold] }
ON COLUMNS,
{YTD([TimeDimension].[2003].[Quarter
4].[December]),YTD([TimeDimension].[2004].[Quarter 4].
[December]) }
DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS
FROM [Sales]
.




Reply With Quote
  #4  
Old   
Steve Pantazis
 
Posts: n/a

Default Re: Need to use variable for year - 09-02-2004 , 06:30 PM



Thanks for the info. This is what I did as a solution, which worked.

I created a parameter called CurrentYear and set its default value to
the expression =Year(Today).

I then converted the MDX query to an expression and substituted
"(YTD([TimeDimension].[2004].[Quarter 4].[December])" with
"(YTD([TimeDimension].[" & Parameters!CurrentYear.Value & "].[Quarter
4].[December])"

The whole MDX query appears below.

="SELECT { [Measures].[Amt Sold zero-filled], [Measures].[Num Sold
zero-filled] } ON COLUMNS, { (YTD([TimeDimension].[" &
Parameters!CurrentYear.Value & "].[Quarter 4].[December]) *
[ProdHierarchy].[Level 04].ALLMEMBERS * [Prod
Description].[Description].ALLMEMBERS ) } DIMENSION PROPERTIES
MEMBER_CAPTION ON ROWS FROM [Sales] WHERE [INum].[INum].[111111] CELL
PROPERTIES VALUE"

"mike" <mike_no_spam (AT) no_spam (DOT) com> wrote

Quote:
Using Reporting Services you'll have to set up parameters for your time
periods you want. Use these parameter values in your dynamic MDX statement.

You can also write some custom code to get the current year and from that
the previous year also. See vb.net date functions.


"Abhinav Kumar" <akumar (AT) itmag (DOT) com.au> wrote in message
news:3cc501c48fba$d0cef690$a601280a (AT) phx (DOT) gbl...
MDX in Analysis Server 2000 does not support parameters
but you can do this programmatically by generating the
MDX dynamically.

Abhinav Kumar
akumar (AT) itmag (DOT) com.au

-----Original Message-----
I'm going crazy. The MDX query below gives me all the
months and
their corresponding sales for a two-year period, which
is what I want.
However, I have no idea how to substitute the hard-
coded year values
with the current year for [2004] and the prior year for
[2003]. Is
there some kind of variable I can use to
set "CurrentYear =
Year(Current_Timestamp)" and "PriorYear = Year
(Current_Timestamp) -1"
or something?

I need to build a report with Reporting Services that
will display
this data. If I leave the hard-coded dates, the report
will be
invalid next year, which is why the current and prior
years need to be
variables rather than hard-coded values.

My TimeDimension levels are set up as Year, Quarter,
Month, and Day.

SELECT { [Measures].[Amt Sold], [Measures].[Num Sold] }
ON COLUMNS,
{YTD([TimeDimension].[2003].[Quarter
4].[December]),YTD([TimeDimension].[2004].[Quarter 4].
[December]) }
DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS
FROM [Sales]
.


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.