dbTalk Databases Forums  

Re: Question about ClosingPeriod function of MDX

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss Re: Question about ClosingPeriod function of MDX in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Olivier Matrat
 
Posts: n/a

Default Re: Question about ClosingPeriod function of MDX - 07-21-2004 , 12:58 PM






Hi

From my perspective the easiest way to achieve this is to incrementaly
update your Time dimension as you update your cube with monthly data; this
way, ClosingPeriod() will obviously always return the last month with data.

However if you wish to create all future (empty) periods in advance, you may
use an MDX expression that filters the months to exclude empty ones and then
get the last member with a value; I am pretty sure this can be done in many
different ways, but here's one that should work (based on the Foodmart 2000
sales cube) :

Tail({NonEmptyCrossjoin({[Time].[Month].Members},{[Measures].[Unit
Sales]},1)},1).Item(0).Item(0)

The NonEmptyCrossjoin() expression returns a set of tuples containing only
the months that have values at their intersection with an arbitrary Measure
(here, Unit Sales)
The Tail() expression returns a set made of one single tuple corresponding
to the last position in the previously filtered set (the Time dimension
being alreday ordered by design)
The first Item(0) expression extracts the single tuple from this set, and
the second one extracts the 1st (and only) member from this tuple.

HTH

Olivier MATRAT

WINSIGHT
Microsoft Gold Certified Partner for Business Intelligence
www.winsight.fr
www.olapwebhouse.com


"Rajesh" <Rajesh (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi All,

I want to get the last month that has data. If I use ClosingPeriod it
always returns the last month in month level whether or not there is data in
last month.
Quote:
Please suggest an alternate way to get the last month that has data.

Thanks



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.