# tim laqua dot comThoughts and Code from Tim Laqua

23Feb/090

## Wierd Slice – Revenue for the Most Recent Hour in the Cube Across the Last 14 Days Sliced by Week

Well - there's two parts to this - one is to figure out the most recent hour in the cube that has data. Let's face it, it finishes as soon as it can - but that time may vary now and then. Then, for this particular report, we wanted to see the last seven days on one series and the previous seven days on another series. To do this, we just slice by two calculated measures. But this creates an odd dateset where the This Week column will have no data for the "Date Time" columns that actually belong to the Previous Week.

This isn't really a problem as in SSRS, you can simply define the Category Group for the Series in your chart (ya, I didn't mention that yet - this is all for a chart) as DatePart("w", Fields!DateTime) - which will group everything by the number of the given weekday and then you can just have your "This Week" and "Prevoius Week" series.

```WITH
MEMBER [Measures].[This Week] AS
Aggregate
([Time].[Calendar Date].LastChild:[Time].[Calendar Date].LastChild.Lag(6)
,[Measures].[Revenue])

MEMBER [Measures].[Previous Week] AS
Aggregate([Time].[Calendar Date].LastChild.Lag(7)
:
[Time].[Calendar Date].LastChild.Lag(13)
,[Measures].[Revenue])
SELECT
NON EMPTY
{[Measures].[Previous Week], [Measures].[This Week]} ON 0
,NON EMPTY
{
[Time].[Date Time].[Date Time].MEMBERS
*
[Time].[24 Hour].[24 Hour].ALLMEMBERS
} ON 1
FROM
(
SELECT
Tail(
Filter(
[Time].[24 Hour].[24 Hour].MEMBERS
,Sum([Time].[Calendar Date].LastChild,[Measures].[Revenue]) > 0
), 1
) ON 0
FROM
(SELECT
{
[Time].[Calendar Date].LastChild
:
[Time].[Calendar Date].LastChild.Lag(13)
} ON 0
FROM [Cube]
)
)
```

And to top it all off - after seeing the chart for a while, nobody liked it (after all, it's a relatively abstract view of revenue) and we dumped it. 😉