dbTalk Databases Forums  

Re: Creating Calculated members

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


Discuss Re: Creating Calculated members in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Matt Carroll [MS]
 
Posts: n/a

Default Re: Creating Calculated members - 08-07-2003 , 01:43 PM






You can create a calculated member that calculates the days using the VBA
functions DateDiff() and CDate(). These are not listed in the functions
list, but they will work. Lookup "Visual Basic for Applications functions"
in books online help to get a complete list of such VBA functions that are
available. To avoid confusion with a measure called CDate you may need to
prefix this function with "VBA!".

E.g.: DateDiff( "d", VBA!CDate( Measures.CDate.Name), VBA!CDate(
Measures.DDate.Name) )

Next you create a hidden member that is simply a count of the entities.

Then you can create another calculated member that calculates the average by
dividing the days by the count .

Hope this helps,
- Matt Carroll
--
This posting is provided "AS IS" with no warranties, and confers no rights.

"devnoronha" <member33654 (AT) dbforums (DOT) com> wrote

Quote:
Does anyone have an idea about creating Calculated members in
Analysis server .
If the following are entries in a table
----------------------------
A B Cdate Ddate
------------------------------
1 K1 1/3/2003 1/6/2003
2 K1 2/3/2003 2/4/2003
3 K2 2/3/2003 2/10/2003

I need to find the Average of the diffrecnce of the 2 dates for each
location (K1 and K2) ie.
avg(DATEDIFF (d,Cdate,Ddate)) .
How do i get this in AS ?
I cannot find an AVG or Datediff function when I go to Edit - New
Calculated Memebr .


In the previous I want the result to show
K1 2 (3 days + 1 day = 4/2 = 2)
K2 7 (7 days = 7/1 = 7)

thnks

--
Dev Noronha


Posted via http://dbforums.com



Reply With Quote
  #2  
Old   
devnoronha
 
Posts: n/a

Default Re: Creating Calculated members - 08-07-2003 , 04:44 PM







Thanks Matt ,
How does one access the cube data in VBA ? I've done VBA scripts for
Excel . Is it the same ?
How exactly does the VBA function know what data to work on (how data is
passed) and how it returns the results ?

Thanks for the reply
Dev

--
Dev Noronha


Posted via http://dbforums.com

Reply With Quote
  #3  
Old   
Magnus Smith
 
Posts: n/a

Default Re: Creating Calculated members - 08-08-2003 , 11:59 AM



You dont use VBA in the way you mention, you still write MDX in the
calculated member definiton.

Within the MDX expression you may refer to VBA functions (e.g. Left,
InStr or DateDiff) and you can pass in strings/numbers, and return
strings/numbers.

If CDate and DDate are the names of your Measures, then create a new
calculated member, within the Measures dimension, and use this MDX
expression:
VBA!DateDiff("d", VBA!CDate([Measures].[CDate]),
VBA!CDate([Measures].[DDate]))

Reply With Quote
  #4  
Old   
devnoronha
 
Posts: n/a

Default Re: Creating Calculated members - 08-11-2003 , 07:10 PM




Thanks Magnus ,
That worked ... it did not give an error while creating the
calculated member ,but at run time i get #ERR in all the cells .
Possibly because some fields have NULL in the 'Cdate' and 'Ddate'
fields . Is that the problem ?

Also, how do I get the Count as Matt suggested ? And after that
the Average .

Thanks a lot

--
Dev Noronha


Posted via http://dbforums.com

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.