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

MDX Dynamic Quarter Values in Calculated Members

$
0
0

Hi all!  

I hope you can help me out with some calculated members I'm working with in a cube.  I need to calculate 4 values to display in a report:

1. Sum of all units sold for all previous quarters
2. Number of units sold for current quarter
3. Sum of units sold for all future quarters
4. Sum of units sold to date (previous + current quarter)

The following MDX works perfectly:  


with 
member [Measures].[SumPreviousQtrs] 
as sum({[DimDate].[Broadcast Yr Qtr].[BQUARTER NAME].&[Q310]:[DimDate].[Broadcast Yr Qtr].[BQUARTER NAME].&[Q312]},[Measures].[Units])

member [Measures].[CurrentQtr] 
as ([DimDate].[Broadcast Yr Qtr].[BQUARTER NAME].&[Q412],[Measures].[Units])

member [Measures].[SumFutureQtrs] 
as sum({[DimDate].[Broadcast Yr Qtr].[BQUARTER NAME].&[Q113]:[DimDate].[Broadcast Yr Qtr].[BQUARTER NAME].&[Q116]},[Measures].[Units])

member [Measures].[SumPrevious+Current] 
as sum({[DimDate].[Broadcast Yr Qtr].[BQUARTER NAME].&[Q310]:[DimDate].[Broadcast Yr Qtr].[BQUARTER NAME].&[Q412]},[Measures].[Units])

select 
{[SumPreviousQtrs],[CurrentQtr],[SumFutureQtrs],[SumPrevious+Current]} on columns,
{[DimAdSalesDetails].[PLAN NUMBER].&[123456]} on rows
from Cube

Now what I need to do is make the current quarter dynamic so as I process the cube each night, this query is aware of the current quarter.  Just to make it more interesting, I need to change the current quarter 14 days after the turn of the calendar quarter.  For example, calendar quarter Q113 starts on January 1, 2013 but our current quarter changes to Q113 on January 15. (Essentially we are running reports for 2 weeks on one quarter before shifting over to the current quarter).  

Example Results:

Now until 1/14/2013:

PlanSumPreviousQtrsCurrentQtrSumFutureQtrsSum Previous+Current
12345610 51015

1/15/2013 and after:

PlanSumPreviousQtrsCurrentQtrSumFutureQtrsSumPrevious+Current
12345615 2817

So on 1/15/2013, the 5 current units moved to the previous quarter, 2 units are now in the current quarter with reduces the future units by 2. 

Any help you can give is greatly appreciated!

--The formatting of my example results got messed up when posted. Try this:

Previous to 1/15/2013:
Plan= 123456
SumPreviousQtrs = 10
CurrentQtr = 5
SumFutureQtrs= 10
SumPrevious+Current = 15


1/15/2013 and after:
Plan= 123456
SumPreviousQtrs = 15
CurrentQtr = 2
SumFutureQtrs= 8
SumPrevious+Current = 17


Viewing all articles
Browse latest Browse all 2472

Trending Articles



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