Imagine today it is the 22nd June 2010 (I've used this date as AdvWrks
cube is old)
I would like to find the set of days that make up this month i.e. 1st June - 22nd June plus the days in the previous 5 equivalent months to date.
So these days would make up the set:
(1st Jan 2010 - 22nd Jan 2010) +
(1st Feb 2010 - 22nd Feb 2010) +
(1st Mar 2010 - 22nd Mar 2010) +
(1st Apr 2010 - 22nd Apr 2010) +
(1st May 2010 - 22nd May 2010) +
(1st Jun 2010 - 22nd Jun 2010)
The following gives me this set of 132 days:
WITH
SET [Days in Current Month] AS
[Date].[Calendar].[Date].&[20100601]:[Date].[Calendar].[Date].&[20100622]
SET [Mths in Past 6 Mths] AS
Tail
(
[Date].[Calendar].[Month].MEMBERS
,6
)
SET [Prev Equiv MTDs] AS
Generate
(
[Mths in Past 6 Mths]
,Head
(
Descendants
(
[Mths in Past 6 Mths].CurrentMember
,[Date].[Calendar].[Date]
,SELF
)
,[Days in Current Month].Count
)
)
SELECT
{} ON 0
,[Prev Equiv MTDs] ON 1
FROM [Adventure Works];
Is it possible to find this set of days without using the Generate
function?
Here is one way:
And here is one more:
And one more...
And this way too:
EDIT
Slow code with non-repeating blocks: