Quantcast
Channel: SQL Server Analysis Services Forum
Viewing all articles
Browse latest Browse all 2472

LastPeriods using Named Sets in Date Hierarchy

$
0
0

I have a cube with [Qty], Fact Table and [Date] Dimension with Hierarchy Year - Month - Week - Date.  I can calculate Qty by Date.  Now I need to aggregate the quantities over 5 days starting at various points in the Hierarchy.  I am trying to create Named Sets to address my need.

WITH
	SET [Last 7 Days] AS
	TAIL(EXISTS([Date].[Date Key].[Date Key].Members,, "Fact Daily T"), 7)

SELECT [Measures].[Qty] ON COLUMNS,

{[Last 7 Days]} ON ROWS

FROM CDC
WHERE [Date].[Year].&[2012]  

This generates:

Date           Qty
2012-07-24 51,594
2012-07-25 54,119
2012-07-26 55,476
2012-07-27 52,508
2012-07-28 3,060
2012-07-30 39,856
2012-07-31 54,779

My problem is that this Set finds the last 7 Days in my dataset.  I need the last 7 Days of the Current Week.  Since the Current week (or last week in my dataset which ends 2012-07-31) ends on Aug 4th.  I need a set with

              Qty This Yr
2012-07-29 (null)
2012-07-30 39,856
2012-07-31 54,779
2012-08-01 (null)
2012-08-02 (null)
2012-08-03 (null)
2012-08-04 (null)

Ultimately, I will need Sets that return the last 7 days of a given hierarchy:  the prior week, prior month and prior year.  This will answer the question of %Change from Last Week, Last Month and Last Year. I Don't have to worry about partial weeks with (null) values.

I do have a DayNumberOfWeek Field in my Date Dimension that I can use to determine the current week hierarchy

Appreciate any ideas.


Mario


Viewing all articles
Browse latest Browse all 2472

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>