tags:

views:

288

answers:

1

I have an MDX query which lists a measure for all 'Week' and 'Day' levels in the OLAP database. For example

SELECT 
{
    HIERARCHIZE( {[Business Time].[Week].members, [Business Time].[Date].members} )
} 
ON ROWS,
{
    [Measures].[Quantity]
} 
ON COLUMNS 
FROM [Sales]

Where the measure is displayed for a Week though, instead of showing the total of all the Day values, I would like to show the value for the last day within the week. For example

Week 1: 12
15 Sept: 10
16 Sept: 20
17 Sept: 12
18 Sept: 15
19 Sept: 8
20 Sept: 9
21 Sept: 12
Week 2: 15
22 Sept: 12
23 Sept: 15

How can I achieve this within the MDX?

+1  A: 

Add a new calculated measures onto the start of your MDX that shows the last day's value only if it is being shown at a week level, otherwise leave it unaltered:

WITH MEMBER [Measures].[Blah] AS 
'IIF(
   [Business Time].currentMember.level.name = "Week",
   ([Business Time].currentMember.lastChild, [Measures].[Quantity]),
   ([Business Time].currentMember, [Measures].[Quantity])
)'

I expect a client asked for this odd request, and I predict you'll get a call in a month from someone in the same office, saying the weekly 'total' is wrong on this report!

Magnus Smith
Actually, it is not that odd a request, if you treat Quantity as a 'Closing Stock amount'. So the closing stock of an item for the week is actually the closing stock of that item on the last day.
Tim C
Good answer. I'd do just one change: use IS to find out what level the member is in. Eg. [Business Time].currentMember.level IS [Business Time].[Week]This is more efficient.
santiiiii