Showing posts with label converting. Show all posts
Showing posts with label converting. Show all posts

Tuesday, March 27, 2012

Calculated Member

I'm trying to add a calculated member to my SSAS 2005 cube. I can calculate what I want using MDX, but I'm having trouble converting my MDX query to the something SSAS understands as a calulated measure.

This is my MDX query.

Working MDX

SELECT

{([Measures].[# of Activities]

,[Geography].[State Name].&[TEXAS]

,[Special Activity Measure].[Special Activity Measure Name].&[Ready to Close]

,[Segmentation].[Segmentation Name].&[Fast Track]

)} ON COLUMNS

,{[Employee].[Emp Full Name].allmembers}ON ROWS

FROM [Employee Scorecard]

WHERE ([EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[34])

Here is my calculated member

Non working calculated member

CREATE MEMBER CURRENTCUBE.[MEASURES].[TX Docs Ready <=10 Days]

AS ([Measures].[# of Activities]

,[Geography].[State Name].&[TEXAS]

,[Special Activity Measure].[Special Activity Measure Name].&[Ready to Close]

,[Segmentation].[Segmentation Name].&[Fast Track]

),

VISIBLE = 1;

scope ([Measures].[TX Docs Ready <=10 Days]);

[EN To Activity Turn Time].[Turn Time Name] = [EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[34];

end scope;

I would also like to add a similar member where the state name is not Texas. How would I do that as well?

I changed my scope. I forgot the "This =" . But it still dosn't work.

Non working calculated member

CREATE MEMBER CURRENTCUBE.[MEASURES].[TX Docs Ready <=10 Days]

AS ([Measures].[# of Activities]

,[Geography].[State Name].&[TEXAS]

,[Special Activity Measure].[Special Activity Measure Name].&[Ready to Close]

,[Segmentation].[Segmentation Name].&[Fast Track]

),

VISIBLE = 1;

scope ([Measures].[TX Docs Ready <=10 Days]);

This = ([EN To Activity Turn Time].[Turn Time Name] = [EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[34]);

end scope;

|||

It appears that you want to sum the activity count for a set of activity turn times, filtered by a specific segmentation and special activity. I would start off by creating a base measure (which you could set to invisible if you want)

Code Snippet

Create MEMBER CurrrentCube.Measures.[Docs Ready <=10 Days]

AS

SUM([EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[34],

([Measures].[# of Activities]

,[Special Activity Measure].[Special Activity Measure Name].&[Ready to Close]

,[Segmentation].[Segmentation Name].&[Fast Track]

),

VISIBLE = 1;

Then creating a TX specific version

Code Snippet

Create MEMBER CurrrentCube.Measures.[TX Docs Ready <=10 Days]

AS

(Measures.[Docs Ready <=10 Days],[Geography].[State Name].&[TEXAS])

Then the non TX can simply be the total, minus the TX measure. You could calculate this by summing a set of all states except TX, but this should be faster

Code Snippet

Create MEMBER CurrrentCube.Measures.[Not TX Docs Ready <=10 Days]

AS

Create MEMBER CurrrentCube.Measures.[Docs Ready <=10 Days]

- Measures.[TX Docs Ready <=10 Days]

|||

I see what your saying. However, I think that by using "Scope" the code would be more readable. I've been playing with it and this is what I have so far.

I can get this to work and it returns values. But it's not exactly what I want.

Code Snippet

CREATE MEMBER CURRENTCUBE.[MEASURES].[Docs Ready <= 7 Days (10 in TX)(Fast Track)]

AS ([Measures].[# of Activities]

,[Special Activity Measure].[Special Activity Measure Name].&[Ready to Close]

,[Segmentation].[Segmentation Name].&[Fast Track]

),

VISIBLE = 1;

scope ([MEASURES].[Docs Ready <= 7 Days (10 in TX)(Fast Track)]);

scope ([Geography].[State Name].&[TEXAS]);

This = [EN To Activity Turn Time].[Turn Time Name].&[34];

end scope;

This = [EN To Activity Turn Time].[Turn Time Name].&[2];

end scope;

What I really want, is something like this

Code Snippet

This = Sum({[EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[34]},[MEASURES].[Docs Ready <= 7 Days (10 in TX)(Fast Track)]);

But when I run this code all I get is empty values.

Code Snippet

scope ([MEASURES].[Docs Ready <= 7 Days (10 in TX)(Fast Track)]);

scope ([Geography].[State Name].&[TEXAS]);

This = Sum({[EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[34]},[MEASURES].[Docs Ready <= 7 Days (10 in TX)(Fast Track)]);

end scope;

This = Sum({[EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[32]},[MEASURES].[Docs Ready <= 7 Days (10 in TX)(Fast Track)]);

end scope;

What am I doing wrong with this scope?

|||

The scope statement is not about readability, it is about restricting the sbucube over which a calculation is performed. I am pretty sure that the second assignment you are doing will just override the previous one that you did for Texas and by summing the measure that you are scoping over, it could be trying to recurse over itself. What I think you want is something more like the following. Assuming that you want to sum over Activity 2-32 if it's not Texas and 2-34 if it is Texas.

Code Snippet

scope ([MEASURES].[Docs Ready <= 7 Days (10 in TX)(Fast Track)]);

This = Aggregate({[EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[32]});

scope ([Geography].[State Name].&[TEXAS]);

This = Aggregate({[EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[34]});

end scope;

end scope;

|||

It dosn't like the aggregate. I've tried both of these and the results are the same as if I never did the scope. I've also tried Sum(Aggregate()) and Sum().

Code Snippet

This = aggregate({[EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[32]},[MEASURES].currentmember);

This = aggregate({[EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[32]});

I feel like I'm really really close but I'm clearly missing an important concept.|||

I'm not exactly sure what the problem is. We are making it hard for the calc engine, telling it that this measure is the sum of itself. Normally I would do an approach like the following.

Code Snippet

-- this is the default calc

CREATE MEMBER CURRENTCUBE.[MEASURES].[Docs Ready <= 7 Days (10 in TX)(Fast Track)]

AS SUM({[EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[32]},([Measures].[# of Activities]

,[Special Activity Measure].[Special Activity Measure Name].&[Ready to Close]

,[Segmentation].[Segmentation Name].&[Fast Track]

)),

VISIBLE = 1;

-- override the calculation for TX

scope ([Geography].[State Name].&[TEXAS]);

([MEASURES].[Docs Ready <= 7 Days (10 in TX)(Fast Track)]) = SUM(

{[EN To Activity Turn Time].[Turn Time Name].&[2]:[EN To Activity Turn Time].[Turn Time Name].&[34]}

,([Measures].[# of Activities]

,[Special Activity Measure].[Special Activity Measure Name].&[Ready to Close]

,[Segmentation].[Segmentation Name].&[Fast Track]

));

end scope;

If this does not work, could you post a simple example of what results you are seeing and what you were expecting.

sql

Calculated measure's MDX formula in (regular) Non-calculated measure

Hi,

This is sort of an extension to my previous question: converting seconds to HH:MM:SS format. I got the MDX formula for that from deepak. but for that i have to create a Calculated measure!!!!

I already have the measures which display seconds, now i have to create a calculated measure which will display the seconds in HH:MM:SS. but I dont want the extra seconds measure to be displayed. I know i can make it visible=false. but this is cumbersome for me because all this is done programmatically using AMO in a program.

so is there a way to provide the MDX formula in the regaular measure itself without having to create a calculated measure.

Thus display/convert the seconds to the HH:MM:SS format in the original measure?

Regards

I forgot one more thing, can we use the "MeasureExpression" and "FormatString" properties of the measure itself? I tried puttin the MDX formula here but it gives a error.|||

Using the MeasureExpression property is the preferred technique to accomplish what you want. It works for the cases I have used it in. What error do you receive, and what is the MDX you're providing as an expression?

PGoldy

|||Only multiplication and division are allowed for measure expression.|||

Hi,

Thanks for the reply.

Here is the scenario with the MDX formula:

Consider that I have a regular measure M1. The measure M1 contains seconds as data. (eg: 400 seconds, 1000 seconds..etc.) currently what I do is whenever I have a measure which contains seconds and has to be displayed in the HH:MM:SS format:

1. I rename the M1 measure as "_M1" and make it visible=false,
2. Then I create a calulated measure with the name M1 and with the formula TimeSerial(0,0,Measures.[_M1]) and FormatString as 'hh:mm:ss'
3. Now the calculated measure M1 contains the the values of seconds formatted to the HH:MM:SS format. example: (TimeSerial(0,0, 37895) = 10:37:35 ; TimeSerial(0,0,1023) = 00:17:03)

What I require is not to create the extra calculated measure M1, but use the TimeSerial(0,0,MeasureName) formula in the regular measure M1. When I put the TimeSerial(0,0,MeasureName) formula in the MDXExpression property and the FormatString as 'hh:mm:ss', I get the following error : "The Cube xxxx cannot be saved because of the following errors: Errors in the metadata manager. The measure expression of the M1 measure is not of the form [measure1]*[measure2] or [measure1]/[measure2]"

Is there a way out for this? what other alternative is possible?

Regards

Friday, February 24, 2012

C#, VB.NET & RS

Is it true thar RServices uses VB.NET syntax for functions (converting types,iif,CDate,..) apart from choosing C# IB project?
AlešYes, check
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSCREATE/htm/rcr_creating_expressions_v1_3983.asp
for details.
--
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
<AG>; "NLB d.d." <AGNLBdd@.discussions.microsoft.com> wrote in message
news:CC0399FA-15B7-417F-B029-2243CC80B288@.microsoft.com...
> Is it true thar RServices uses VB.NET syntax for functions (converting
types,iif,CDate,..) apart from choosing C# IB project?
> Aleš