Friday, March 30, 2012

Named set using LastPeriods (but not all of them)

To get the current period we have a named set Current Period. To get the last 13 periods we have a named set Last 13 Periods. We can aslo detect period that are not period 14.

Period 14 is an oddball period and I want to skip over it i.e Last 12 Periods will aways show data for the previuous 12 periods that were not periods 14s.

How do we link all of this to give the last 13 periods which were not a period 14?

Many thanks this is driving me bonkers.
Mark.

Code Snippet

CURRENT PERIOD
{
Filter([Alt Week Calendar].[Accounting Period].Members, [Alt Week Calendar].Currentmember.Properties("Period14")="1")
}

LAST 13 PERIODS
{LastPeriods
(13,Filter([Alt Week Calendar].[Accounting Period].Members,[Alt Week Calendar].Currentmember.Properties("Current Period")<>"0").Item(0))
}

NOT PERIOD 14
{
Filter([Alt Week Calendar].[Accounting Period].Members,[Accounting Week Calendar].Currentmember.Properties("Period14")<>"1")
}

Hi Mark,

Here's an example from Adventure Works which returns the last three days that aren't weekends:

Code Snippet

with member measures.demo as

generate(

tail(

exists(

[Date].[Date].currentmember.lag(5):[Date].[Date].currentmember

, [Date].[Day Name].&[2]:[Date].[Day Name].&[6])

,3)

, [Date].[Date].currentmember.name + " (" + [Date].[Date].currentmember.properties("Day Name") + ")", ", ")

select measures.demo on 0,

[Date].[Date].[Date].members on 1

from [Adventure Works]

What I'm doing here is finding the last five days, using an exists to get only the days from that set which are weekdays, then finding the last three days in the resulting set. The outermost Generate() is simply there to display the results of the expression in an easy-to-read way.

HTH,

Chris

No comments:

Post a Comment