Quantcast
Channel: SQL Server Analysis Services Forum
Viewing all articles
Browse latest Browse all 2472

MDX Passing a table driven value

$
0
0

Hi all!  I need some help with passing a parameter to a calculated member within a cube.  The calculated member below works perfectly.  But notice the hard coded value of 14 to determine the days lag into the next quarter (i.e we run the reports for 14 days into the next quarter before shifting over to the current quarter).  It appears 3 times in this calculated member and there are 16 calculated members to maintain.  If the business decides to change the lag to 7 days, I have to change it in 42 different locations.  Bad design!  

I have a table in the source system that contains the days lag parameter.  How can I retrieve the parameter, bring it into the cube and then pass it to this calculated member?   

 

CREATE MEMBER CURRENTCUBE.[Measures].UnitsSumFutureQtrs
 AS 
iif(VBAMDX.Day(VBAMDX.Now()-14)<10,
StrToValue("sum({ParallelPeriod( [DimDate].[Broadcast Yr Qtr Day].[Bcast Qtr],-1,[DimDate].[Broadcast Yr Qtr Day].[Bcast Day].[" + VBAMDX.Format(VBAMDX.Now()-14,"MM/d/yyyy") + "].parent):NULL},[Measures].[Units])"),
StrToValue("sum({ParallelPeriod( [DimDate].[Broadcast Yr Qtr Day].[Bcast Qtr],-1,[DimDate].[Broadcast Yr Qtr Day].[Bcast Day].[" + VBAMDX.Format(VBAMDX.Now()-14,"MM/dd/yyyy") + "].parent):NULL},[Measures].[Units])")
)

What this calculated member does:
1. using the current date, determine the date 14 days ago  -- VBAMDX.Format(VBAMDX.Now()-14,"MM/d/yyyy")
2. Look up quarter name from the Broadcast Yr Qtr Day hierarchy -- .parent
3. Find the quarter name of one period in the future --    parrallelperiod -1
4. Use this future value to pass a range to the sum function (Null goes to the furthest point in the cube) to sum the number of units sold in future quarters -- sum({quarter name of one period in the future:NULL},[Measures].[Units])
5. Uses StrToValue to imbed the VBAMDX functions in the member
6. Iif statement determines if the lag day is a single or double (e.g. 12/5/2012 vs. 12/12/2012) to get the right format string.

Thanks for any help you can give!


Viewing all articles
Browse latest Browse all 2472

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>