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


Cumulative Sum via Calculated Measure


Cumulative Sum via Calculated Measure

Author
Message
rossnruthie
rossnruthie
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 200
Hey all I'm hoping you can help me with an MDX problem I am having. I will use adventure works for this example. Basically I have been asked to create a calculated measure in the cube that will display a cumulative or rolling sum of another measure. I have found quite few solutions but all of them use a specific dimension such as date with YTD in the SUM but I was hoping to create a measure that was not dependent on any specific dimension.

The simplest MDX I could find is in the example below. While this works in MDX on the fly, I can't use it in Excel in any other dimension besides the product line. I was hoping there was a way to make it dynamic so that it would provide the cumulative sum no matter what dimensions are dropped on.

I was thinking that i would have to somehow use the Descendants function with a specified Axis but my knowledge of MDX is so limited that I am probably way off. Any ideas?

with member [Measures].[Running total] as
Sum(null : [Product].[Product Line].CurrentMember, [Measures].[Internet Sales Amount]),
Format = "Currency"

select {[Measures].[Internet Sales Amount],[Measures].[Running total]} on 0,
[Product].[Product Line].[Product Line].Members on 1
from [Adventure Works]


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: 1291 Visits: 2404
Something like this would work:

WITH MEMBER [C]
AS
SUM(NULL:Axis(1).Item(0).Item(Axis(1).Item(0).Count-1).Hierarchy.CurrentMember, [Measures].[Your Measure])

SELECT
{[Measures].[Your Measure], [c]} ON 0,
[Your Dimension].[Your Hierarchy or Attribute] ON 1
FROM
[Your Cube]




Hope that helps :-)




I'm on LinkedIn
bonamim.jb
bonamim.jb
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 63
Please,

Help me.

With a dimension works.

If you use two attributes of the same dimension:

Year;
Month.

Does not work.

Example 01:

WITH
MEMBER [Measures].[SALDO_INICIAL] AS SUM(NULL:Axis(1).Item(0).Item(Axis(1).Item(0).Count-1).Hierarchy.PREVMEMBER, [Measures].[QTDE_TOTAL_ENTRADAS] - [Measures].[QTDE_TOTAL_SAIDAS])
MEMBER [Measures].[SALDO_FINAL] AS SUM(NULL:Axis(1).Item(0).Item(Axis(1).Item(0).Count-1).Hierarchy.CurrentMember, [Measures].[QTDE_TOTAL_ENTRADAS] - [Measures].[QTDE_TOTAL_SAIDAS])

SELECT
{
[Measures].[SALDO_INICIAL],
[Measures].[QTDE_TOTAL_ENTRADAS],
[Measures].[QTDE_TOTAL_SAIDAS],
[Measures].[SALDO_FINAL]
} ON 0,
[DATAS].[MES].[MES] ON 1
FROM
[Model]


Attachment: img1.jpg

Example 02:

WITH
MEMBER [Measures].[SALDO_INICIAL] AS SUM(NULL:Axis(1).Item(0).Item(Axis(1).Item(0).Count-1).Hierarchy.PREVMEMBER, [Measures].[QTDE_TOTAL_ENTRADAS] - [Measures].[QTDE_TOTAL_SAIDAS])
MEMBER [Measures].[SALDO_FINAL] AS SUM(NULL:Axis(1).Item(0).Item(Axis(1).Item(0).Count-1).Hierarchy.CurrentMember, [Measures].[QTDE_TOTAL_ENTRADAS] - [Measures].[QTDE_TOTAL_SAIDAS])

SELECT
{
[Measures].[SALDO_INICIAL],
[Measures].[QTDE_TOTAL_ENTRADAS],
[Measures].[QTDE_TOTAL_SAIDAS],
[Measures].[SALDO_FINAL]
} ON 0,
(
[DATAS].[ANO].[ANO],
[DATAS].[MES].[MES]
) ON 1
FROM
[Model]


Attachment: img2.jpg
Attachments
img1.jpg (5 views, 39.00 KB)
img2.jpg (4 views, 51.00 KB)
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