dbTalk Databases Forums  

Can this nasty IIF statement be replaced?

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


Discuss Can this nasty IIF statement be replaced? in the microsoft.public.sqlserver.olap forum.



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

Default Can this nasty IIF statement be replaced? - 01-04-2005 , 10:17 AM






In my cube I have a Time Dimension CRM Date and a Session dimension. The
session dimension essentially tracks when the cube was processed. So there
is one for November, one for December, etc. Each session that is processed
contains all the data for all time. It is a nice way to give some point in
time capabilities in the cube.

So I have a calculated member where I sum up all my amounts for the selected
CRM Date (or last date if the All level is selected). Problem is, after I
process December and my CRM Date dimension contains days for december, when I
look back at my November session, it calculates to 0. This is because the
"last date" of the CRM Date dimension contains no data in the novemeber
session.

I have this IIF statement too chose which date to end on:

IIF ( CDate(Tail(Descendants([CRM
Date].CurrentMember,,Leaves),1).Item(0).Properties("CRM Date")) <
CDate([Session].CurrentMember.Properties("Session Date")),
TupleToStr(Tail(Descendants([CRM Date].CurrentMember,,Leaves),1).Item(0) ),
Format(
[Session].CurrentMember.Properties("Session Date"),
"""[CRM Date].[Year].&[" + [Session].CurrentMember.Properties("FYYear") +
"].&[""" + [Session].CurrentMember.Properties("FYQuarter") +
"""].&[""yyyymm""].&[""yyyymmdd""]"""
)
)

As you can see, ugly and it's also very slow since I reuse the same code in
multiple calculated measures. Any suggestions on how to improve the speed or
architect this better?

Reply With Quote
  #2  
Old   
Jeff A. Stucker
 
Posts: n/a

Default Re: Can this nasty IIF statement be replaced? - 01-04-2005 , 10:46 AM






What are you trying to accomplish? A little explanation will help so others
don't have to first reverse engineer your code sample.

--
Cheers,

'(' Jeff A. Stucker
\

Business Intelligence
www.criadvantage.com
--------------------------------------
"Twig" <Twig (AT) discussions (DOT) microsoft.com> wrote

Quote:
In my cube I have a Time Dimension CRM Date and a Session dimension. The
session dimension essentially tracks when the cube was processed. So
there
is one for November, one for December, etc. Each session that is
processed
contains all the data for all time. It is a nice way to give some point
in
time capabilities in the cube.

So I have a calculated member where I sum up all my amounts for the
selected
CRM Date (or last date if the All level is selected). Problem is, after I
process December and my CRM Date dimension contains days for december,
when I
look back at my November session, it calculates to 0. This is because the
"last date" of the CRM Date dimension contains no data in the novemeber
session.

I have this IIF statement too chose which date to end on:

IIF ( CDate(Tail(Descendants([CRM
Date].CurrentMember,,Leaves),1).Item(0).Properties("CRM Date"))
CDate([Session].CurrentMember.Properties("Session Date")),
TupleToStr(Tail(Descendants([CRM
Date].CurrentMember,,Leaves),1).Item(0) ),
Format(
[Session].CurrentMember.Properties("Session Date"),
"""[CRM Date].[Year].&[" + [Session].CurrentMember.Properties("FYYear") +
"].&[""" + [Session].CurrentMember.Properties("FYQuarter") +
"""].&[""yyyymm""].&[""yyyymmdd""]"""
)
)

As you can see, ugly and it's also very slow since I reuse the same code
in
multiple calculated measures. Any suggestions on how to improve the speed
or
architect this better?



Reply With Quote
  #3  
Old   
Twig
 
Posts: n/a

Default Re: Can this nasty IIF statement be replaced? - 01-04-2005 , 12:57 PM



Sure. This IIF statement essentially defines the set I sum across. So my
calculated measure is:

SUM(Measures.[Amount], IIF(...))

The IIF itself is determining which is the last available date that I can
use to SUM across. If the CRM Date selected is less then the SessionDate
Property of my Session dimension, it uses the CRM Date. If the SessionDate
is less, it uses the CRMDate leaf that matches that date. If no CRM Date is
selected, it gets the last leaf and treats it as the selected one.


"Jeff A. Stucker" wrote:

Quote:
What are you trying to accomplish? A little explanation will help so others
don't have to first reverse engineer your code sample.

--
Cheers,

'(' Jeff A. Stucker
\

Business Intelligence
www.criadvantage.com
--------------------------------------
"Twig" <Twig (AT) discussions (DOT) microsoft.com> wrote in message
news:9223DB20-BA46-433F-8168-4D124597013F (AT) microsoft (DOT) com...
In my cube I have a Time Dimension CRM Date and a Session dimension. The
session dimension essentially tracks when the cube was processed. So
there
is one for November, one for December, etc. Each session that is
processed
contains all the data for all time. It is a nice way to give some point
in
time capabilities in the cube.

So I have a calculated member where I sum up all my amounts for the
selected
CRM Date (or last date if the All level is selected). Problem is, after I
process December and my CRM Date dimension contains days for december,
when I
look back at my November session, it calculates to 0. This is because the
"last date" of the CRM Date dimension contains no data in the novemeber
session.

I have this IIF statement too chose which date to end on:

IIF ( CDate(Tail(Descendants([CRM
Date].CurrentMember,,Leaves),1).Item(0).Properties("CRM Date"))
CDate([Session].CurrentMember.Properties("Session Date")),
TupleToStr(Tail(Descendants([CRM
Date].CurrentMember,,Leaves),1).Item(0) ),
Format(
[Session].CurrentMember.Properties("Session Date"),
"""[CRM Date].[Year].&[" + [Session].CurrentMember.Properties("FYYear") +
"].&[""" + [Session].CurrentMember.Properties("FYQuarter") +
"""].&[""yyyymm""].&[""yyyymmdd""]"""
)
)

As you can see, ugly and it's also very slow since I reuse the same code
in
multiple calculated measures. Any suggestions on how to improve the speed
or
architect this better?




Reply With Quote
  #4  
Old   
Deepak Puri
 
Posts: n/a

Default Re: Can this nasty IIF statement be replaced? - 01-04-2005 , 08:30 PM



By avoiding iif() and the associated need to convert tuples to strings,
a simpler expression can be constructed (don't know if it improves
performance, though):

Quote:
Head(Hierarchize(Union(Tail(Descendants(
[CRM Date].CurrentMember,,Leaves)),
Filter([CRM Date].[Day].Members,
[CRM Date].Properties("CRMDate") =
[Session].Properties("Session Date"))))).Item(0)
Quote:

- Deepak

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


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.