Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Cumulative Totals over specific Date Range


Cumulative Totals over specific Date Range

Author
Message
Ludo-ZX7R
Ludo-ZX7R
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 Visits: 789
Hi all,

I would like to implement a running total of a measure over Days, Weeks, Months, ... in an MDX query and ultimately as a Calculation in my Cube.

I know that there are a lot of articles out there and I have found a few solutions but none of which works within the context of a specific Date Rage.

Setting:
Time Dimension [DimTime].[Date].[Date] and [DimTime].[Week].[Week]

Measure to aggregate: Measure.Hits

If I run the following query:
WITH
   MEMBER Measures.toto AS
      Aggregate({[DimTime].[Date].[Date].Members.Item(0):[DimTime].[Date].currentmember}, [Measures].[Hits]))

SELECT
    {Measures.[Hits], Measures.toto} ON 0,
   NON EMPTY   [DimTime].[Date].[Date] ON 1
FROM
    [My Cube]


It works fine however if I had a specific Date Range in the "WHERE" Clause or directly in the "SELECT", it aggregates values outside the Date Range.

To simplify, I would like the aggregation to start at the first Date in the Query and not before.

I have played with Aggregate, Sum, ... and no joy. :-(

I'm sure some of you will point out what I have stupidly missed.

Cheers
PB_BI
PB_BI
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1288 Visits: 2393
Change the first part of your range in your calculation to Axis(1).Item(0)

So in AdventureWorks the example would be:

WITH
MEMBER Measures.toto AS
Aggregate({Axis(1).Item(0):[Date].[Date].currentmember},
[Measures].[Order Count])

SELECT
{[Measures].[Order Count], Measures.toto} ON 0,
NON EMPTY {[Date].[Date].&[20060301]:[Date].[Date].&[20060331]} ON 1
FROM
[Adventure Works]





I'm on LinkedIn
Ludo-ZX7R
Ludo-ZX7R
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 Visits: 789
Hi

Thanks for this solution which works fine.

Having said that, it only works if the Data Range is specified in the SELECT part of the query.

If I put the Range in the WHERE Clause, it still aggregates/sum from all the previous dates.

Thanks for spending the time helping me!

I'll carry on digging and will put a solution ... if/when I find one.

Cheers
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search