dbTalk Databases Forums  

How to calculate a sum for a rolling period (e.g.; last 7 days)?

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


Discuss How to calculate a sum for a rolling period (e.g.; last 7 days)? in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Steven H
 
Posts: n/a

Default How to calculate a sum for a rolling period (e.g.; last 7 days)? - 08-23-2006 , 10:40 AM






If we have a measure that is number of sales orders per day [Sales Order
Count], how would we write an MDX statement that will return the sum of
Sales Order Count for the last "X" days, such that if the cutrrent member is
Monday 8/21/2006 and we want the last 7 days sun, we get sum of Sales Order
Count from 8/15/2007 - 8/21/2006?

Thanks!



Reply With Quote
  #2  
Old   
Jéjé
 
Posts: n/a

Default Re: How to calculate a sum for a rolling period (e.g.; last 7 days)? - 08-23-2006 , 11:39 AM






something like:
sum(
{time.currentmember.lag(7):time.currentmember}, measures.[Sales Order
Count])



"Steven H" <steven.heinz (AT) ilg (DOT) com> wrote

Quote:
If we have a measure that is number of sales orders per day [Sales Order
Count], how would we write an MDX statement that will return the sum of
Sales Order Count for the last "X" days, such that if the cutrrent member
is Monday 8/21/2006 and we want the last 7 days sun, we get sum of Sales
Order Count from 8/15/2007 - 8/21/2006?

Thanks!




Reply With Quote
  #3  
Old   
ZULFIQAR SYED
 
Posts: n/a

Default Re: How to calculate a sum for a rolling period (e.g.; last 7 days)? - 08-23-2006 , 08:03 PM



Steven,

Please try LASTPERIODS function in case you are using AS2005. Here is a
test script against Adventure Works DW in the samples.

with
member measures.x as
sum(
{
lastperiods(
7,
[Date].[Calendar].[Date].&[629]
)
}
,
[Measures].[Internet Sales Amount]
)
select
{
lastperiods(
7,
[Date].[Calendar].[Date].&[629]
)
} on 1
,
{
[Measures].[Internet Sales Amount]
,
measures.x
}
on 0
from
[Adventure Works]

HTH..

ZULFIQAR SYED
HTTP://ZULFIQAR.TYPEPAD.COM


Steven H wrote:
Quote:
If we have a measure that is number of sales orders per day [Sales Order
Count], how would we write an MDX statement that will return the sum of
Sales Order Count for the last "X" days, such that if the cutrrent member is
Monday 8/21/2006 and we want the last 7 days sun, we get sum of Sales Order
Count from 8/15/2007 - 8/21/2006?

Thanks!


Reply With Quote
  #4  
Old   
Jeje
 
Posts: n/a

Default Re: How to calculate a sum for a rolling period (e.g.; last 7 days)? - 08-23-2006 , 08:35 PM



good, this is the function I'm looking for but my memory has decide to not
help me ;-)
lastperiods is more easy to use and to read.

"ZULFIQAR SYED" <datagig (AT) gmail (DOT) com> wrote

Quote:
Steven,

Please try LASTPERIODS function in case you are using AS2005. Here is a
test script against Adventure Works DW in the samples.

with
member measures.x as
sum(
{
lastperiods(
7,
[Date].[Calendar].[Date].&[629]
)
}
,
[Measures].[Internet Sales Amount]
)
select
{
lastperiods(
7,
[Date].[Calendar].[Date].&[629]
)
} on 1
,
{
[Measures].[Internet Sales Amount]
,
measures.x
}
on 0
from
[Adventure Works]

HTH..

ZULFIQAR SYED
HTTP://ZULFIQAR.TYPEPAD.COM


Steven H wrote:
If we have a measure that is number of sales orders per day [Sales Order
Count], how would we write an MDX statement that will return the sum of
Sales Order Count for the last "X" days, such that if the cutrrent member
is
Monday 8/21/2006 and we want the last 7 days sun, we get sum of Sales
Order
Count from 8/15/2007 - 8/21/2006?

Thanks!




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.