Showing posts with label measures. Show all posts
Showing posts with label measures. Show all posts

Thursday, March 8, 2012

Calling .Net Assembly

I create a KPI with the following expression:

([Measures].[TDV Result],

StrToMember("[TDV Result Date].[Year - Quarter - Month - Date]

.[Month].&[" + MdxFunctions.MdxFunctions.Timeframe.GetCurrentMonth() + "]"),

[Entities].[EntityType].[Site],

[TDVs].[Parameter - Material].&[Coal])

MdxFunctions.MdxFunctions.Timeframe.GetCurrentMonth() is a .Net assembly and returns a string like 2007-02-01. I deploy and look at the Browser View but there is an error stating that "The '2007-02-01' string cannont be converted to the date type". How do I convert the date string?

You are passing 2007-02-01 as a key, are you sure that key of the time dimension is a string and not a date? You should either pass a key or remote &: ("[TDV Result Date].[Year - Quarter - Month - Date].[Month].["|||

I'm not entirely sure, but if I had to guess I would try adding the time component. If you are using a date datatype for the key of your month attribute, it might be expecting a value in the form of "yyyy-mm-dd hh:mm:ss"

A couple of other observations:

I think you should be able to write your .Net function to return an actual member instead of a string, which mean you would not need the StrToMember Call everytime you used GetCurrentMonth (You could look at the LinkMember function from http://www.codeplex.com/ASStoredProcedures )|||Thanks, I did notice I was missing the time part after I sent this post. I would like to just use VBA but the problem is I have other functions to get the current week, quarter, and other functions that require lengthy VBA code. If I put it in a calculation then I need to duplicate it for every cube. I tried the Time Intelligence but only get NA.|||

That's cool, I realise that there are more considerations than pure speed. :)

I just thought you should be aware that there is a performance impact, particularly if you had queries that displayed the KPI for a large number of members. But if you are now up and running and the performance is acceptable then there is no need to worry.

Friday, February 24, 2012

calculations memory error

Deleted the measure part of a cube (by mistake) and put them back again (the same measures).

It works fine. All measures were there and all calculations when browsing the cube.

but I cannot change the calculations. "internal memory error corruption" (or like),

They don't show up in the calculations.

How can I get back my calculations?

Process the cube : no errors but still no calculations

There was a known bug in the BI Dev Studio in the calculation tab which caused this error. Upgrading to SP2 should solve this.

Calculations involving NULLs

I have a Calulated Member that is calculating an average.
[Measures].[Overall Satisfaction]/[Measures].[Count Of Survey]
The problem is that for some of the items there are no surveys, so there are
NULL values in the database for these.
When I view the cube as a pivot table in Excel I am getting #NUM! for any
dimentions that do not have actual numbers.
How can I change my calculation so it will just return NULL instead of the
dreaded #NUM! value that drives managers so crazy?
Thank you!
:-J
Jeremy
Use COALESCE or ISNULL function to change a NULL to a valid value or a
space.
Anith
|||REGARDS MY EXAMPLE
[Measures].[Average] AS ' IIF(ISNULL([Measures].[Count Of Survey]), NULL, [Measures].[Overall Satisfaction]/[Measures].[Count Of Survey]) '
You colud use ISNULL() with a tuple, for example ISNULL(([Time].[2004].CURRENTMEMBER, [Measures].[Overall Sastisfaction))
I hope it would help you
Agustin
|||Thank you for the help it got me going on the right track.
What I ended up with was:
IIF([Measures].[Count Of Survey]=0, NULL, [Measures].[Overall
Satisfaction]/[Measures].[Count Of Survey])
This seems to work perfectly!
Thanks agian!
-Jeremy
"Agustin Brau" <anonymous@.discussions.microsoft.com> wrote in message
news:759562E4-29AE-4697-AEE4-4290AF5A524D@.microsoft.com...
> REGARDS MY EXAMPLE
> --
> [Measures].[Average] AS ' IIF(ISNULL([Measures].[Count Of Survey]), NULL,
[Measures].[Overall Satisfaction]/[Measures].[Count Of Survey]) '
> --
> You colud use ISNULL() with a tuple, for example
ISNULL(([Time].[2004].CURRENTMEMBER, [Measures].[Overall Sastisfaction))
> I hope it would help you
> Agustin

Tuesday, February 14, 2012

Calculating Median value from measures and dimensions

I am facing some problem in calculating Median

I am trying to calculate the median value using one of the measures and a dimension value.

Time is a measure in my cube and OpId is one of the dimensions.The result is as follows:

opid time median

1 55

2 23

3 23

Total 23

The Time here for Op Id 1 is the aggregation for all the rows whose OpId is 1.I want the median of the values whose OpId is 1 which is not showing at the moment.

What I am getting here is the median for all of the OpId but what I really want is the median for each of the individual Opid's as well.

I am using a calculated field Median with the following expression.

MEDIAN

( [Dim Operation].[Dim Operation].currentmember.children ,[Measures].[Elapsed Time])

Thanks

I think the reason you're getting a null for the first three rows is that the .Children function won't return any members if you're at the leaf level already. Instead, you'll want to use the Descendants function. Something like the following should do the trick:

Median(

Descendants([Dim Operation].[Dim Operation].CurrentMember, ,LEAVES)

,[Measures].[Elapsed Time]

)

Now if you're expecting to calculate a median value for opid 1 for more than simply the opid 1 value, then you'll need to add another dimension to the equation.

Calculating last non empty of measures that are not included in a month

Hi!

I have two tables.

One is measures like this

Product Measure Date

Prod A 10 12, Jan 2006

Prod A 15 20, Jan 2006

Prod A 11 5, Mar 2006

The other is time dimension

When I create a cube, I would like to see by months last value of measure.

So in Feb I should get 15.

My question is - should I create a query and run it on server to

1. Find which months are not icluded in measuers

2. Then find last value for each product

3. Write into new table measures, where February will have last non empty value from January?

Or can I do it cube in some way?

The best way to solve this in AS2005 is to define measure aggregation function as LastNonEmpty - it will do exactly what you need.

Sunday, February 12, 2012

Calculating AVG Values

Hi mates,


Code Snippet

WITH
MEMBER [MEASURES].X AS AVG([MEASURES].[ITEM VALUE])
MEMBER MEASURES.PARENTID

AS [DEPARTMENT].DEPARTMENTS].CURRENTMEMBER.PARENT.NAME

MEMBER MEASURES.CHILDRENID AS
GENERATE(DESCENDANTS([DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER),
[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER.NAME, " - ")
MEMBER MEASURES.CHILDRENNAME AS
GENERATE(DESCENDANTS([DEPARTMENT].[DEPARTMENT].CURRENTMEMBER),
[DEPARTMENT].[DEPARTMENT].CURRENTMEMBER.NAME, " - ")
SELECT
CROSSJOIN([TIME].YEAR.&[2006], [TIME].[DATEHIER].[MONTH].MEMBERS,
DESCENDANTS([DEPARTMENT].[2],
[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER, SELF_AND_BEFORE)) ON ROWS ,

{(MEASURES.PARENTID), (MEASURES.CHILDRENID), (MEASURES.CHILDRENNAME),

[MEASURES].X} ON COLUMNS

FROM OLAPDEV
WHERE ([ITEM].[78])

this MDX Query returns the following result


Year
Month
Department
Department ParentId
Department ChildrenIds
Department ChildrenNames
ItemValue (Measure Value)

This returns sum of Item value for each month,year and deparmemnt.

But I need Avg of Item Values for each month, year and department

please help me


thanks

anand

You have an "Item Value" measure defined. Add another measure which is the Count aggregate function instead of the Sum aggregate function. Now that you have the Sum and the Count, you can simply do Sum/Count and calculate the average. So your MDX would start like the following:

WITH
MEMBER [MEASURES].X AS IIf(IsEmpty([MEASURES].[ITEM VALUE COUNT]),null,[MEASURES].[ITEM VALUE]/[MEASURES].[ITEM VALUE COUNT])

|||

It is not returning the correct value,

could not get count for each year, month and by department.

count to be calculated , using group of year, month and department,

but by above solution i couldn't get that

|||You're going to need to give us more info if you want our help. We can't read your mind. What precisely is wrong? What is the correct value? What is currently being returned?|||

Code Snippet

WITH

MEMBER [MEASURES].X AS [MEASURES].[ITEM VALUE]

MEMBER MEASURES.PARENTID AS

[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER.PARENT.NAME MEMBER

MEASURES.CHILDRENID AS

GENERATE(DESCENDANTS([DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER),

[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER.NAME, " - ")

MEMBER MEASURES.CHILDRENNAME AS

GENERATE(DESCENDANTS([DEPARTMENT].[DEPARTMENT].CURRENTMEMBER),

[DEPARTMENT].[DEPARTMENT].CURRENTMEMBER.NAME, " - ")

SELECT

CROSSJOIN([TIME].YEAR.&[2006],

[TIME].[DATEHIER].[MONTH].MEMBERS,

DESCENDANTS([DEPARTMENT].[2],

[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER, SELF_AND_BEFORE)) ON ROWS ,

{(MEASURES.PARENTID), (MEASURES.CHILDRENID),

(MEASURES.CHILDRENNAME), [MEASURES].X} ON COLUMNS

FROM IBMTEST

WHERE ([ITEM].[78])

above query returns following results, which returns sum of itemvalue group by year, month, department.

Year #Month #Department #Parent.Dept #Child.deptIDs #Child.DeptNames #Value

2006 1 2 2 2 All - Corporate 337710

2006 2 2 2 2 All - Corporate 328059

2006 3 2 2 2 All - Corporate 432346

2006 4 2 2 2 All - Corporate 342362

2006 5 2 2 2 All - Corporate (null)


my requirement is avg(itemvalue) group by year, month and department.

WITH
MEMBER [MEASURES].X AS IIf(IsEmpty([MEASURES].[ITEM VALUE COUNT]),null,[MEASURES].[ITEM VALUE]/[MEASURES].[ITEM VALUE COUNT])

if i use your above calculated member it gives error for using item [MEASURES].[ITEM VALUE COUNT],

WITH
MEMBER [MEASURES].X AS IIf(IsEmpty( COUNT([MEASURES].[ITEM VALUE])),null,[MEASURES].[ITEM VALUE]/ COUNT([MEASURES].[ITEM VALUE]))

i removed count and used count(measures.itemvalue), this is also returing the same value as sum. even using AVG(MEASURES.ITEMVLAUE) also not

working.

i think this is not working out since crossjoin is used. i hope this is more clear to u.

Friday, February 10, 2012

Calculated/derived measures

Hello again.

I'm wondering if it's possible to add some form of calculated field to my fact table.

Scenario... I have a fact table that records customer account balances a the end of each day. As this is a bank we're talking about, some of the balances are in credit & some overdrawn.

Since the AccountBalance field aggregates by default to sum, if for example I wish to view balances by product I get the NET balances (i.e. all debit & credit balances summed). This is OK, however obviously my people will want to be able to split these in to

Credit Balances

Product

a 100

b 100

c 100

Debit Balances

Product

a -50

b -50

c -50

as opposed to the current situation where I get

Balances

Product

a 50

b 50

c 50

Hope this is clear... question is... how do I go about it ? Calculated field, derived field... I tried a simple IIF calculation but the trouble is it went something like

IIF([measures].[FactAccountBals] >=0, [measures].[FactAccountBals] ,0)

to give me credit balances, however (as you can imagine) it returns ZERO for all debit balance accounts, whereas I want to ignore them... but how ?

You can make another column in your fact table that is either "Credit" or "Debit" and then make an attribute out of that.

Then you can add that attribute to your mdx statement and have items broken out by transaction type.

|||Sorry, stupid question, but how do I make an attribute out of a fact table field record ?|||

OK for anyone else here's what I ended up doing.

Created a New Dimension called Dim Baltype with just 2 records, Debit Bal & Credit Bal

Then ran an update query on the fact table where I added and extra field to signify Dr or Cr balance & linked that to Dim Baltype - This now enables me to split by Loans and deposits in the cube.

Thanks for the steer

Calculated Members when generating a report model

I created and deployed calculated member as measures in my cube but when I generate a model in Reporting services the calculated members do not appear? Should they? or did I miss something? Anyone else experience this?

Thank you!

In get calculated members (calculated meaures) to surface in a report model, they have to be associated with a measure group. On the calculations tab in BIDS, click on the Calculation Properties button on the menu bar and then associate each calculated measure with a measure group. Recreate your report model and they should appear along with the measures that belong to that measure group.

HTH,

Dave Fackler

|||

Thank you, that was it! They are there now when I re-generate the model.

Janet

Calculated Members

Hi, I deployed a cube in SSAS with two dimensions and several measures. I browsed the data after deploying and processing the cube and the data displayed correctly in the grid for all the measures.
After that I created a simple calculated member (like adding two measures) and then deployed and processed the cube again.
after that I browsed the data, every measure for every dimension were empty.(not 0 just empty).
Does anyone know the reason for this?
pls mail me supunthri@.gmail.com
Supun
You probably removed that Calculate; statement when you added the measure.

You can read this for a similar problem..

Chris
|||Hey Cris,
You were right, there was no Calculate; statement in the script,
Thanx a lot
Best Regards!
Supun

Calculated member wrong behaviour in Reporting Services

Hello,

I've created a SQL Server2005 AS Cube with a YTD calculated member:

Sum (YTD(),[Measures].[measure X])

This member (and others give the right results in the cube browser as well in an Excel pivot table). In a parameterized (year-month) report in Reporting services this does not work. It gives only the data of the given moth instead of the sum of all the months in the given year.

Can somebody help me with this issue?

Thanks!

Pieter

Hi Pieter,

What is the MDX query used in the report and what does your time dimension look like - I'm assuming that this problem occurs even with a fixed (no parameters) query?

|||

Thanx for your reply,

the YTD measures work correctly now both in the AS browser as in Reporting services, I redesigned the time dimension in AS. The only member whis does'nt work correctly in RS is a year total. this total works correct in the AS browser and also in RS without a parameter on time (month). It has to return the yeartotal regardless on what time is given in the parameter

The member looks as follows:

Measure Y:

sum(ancestors([Time dimension].[Hierarchy Year-Halfyear-Quarter-Month-Day].currentmember,[Time dimension].[Hierarchy Year-Halfyear-Quarter-Month-Day].[Year]),[Measures].[Measure X])

This is the MDX quert which is generated by RS:

SELECT NON EMPTY { [Measures].[Measure Y], [Measures].[Measure X] } ON COLUMNS FROM ( SELECT ( STRTOSET(@.Timedimensionhierarchyyearmonth, CONSTRAINED) ) ON COLUMNS FROM [ Cube]) WHERE ( IIF( STRTOSET(@.Timedimensionhierarchyyearmonth, CONSTRAINED).Count = 1, STRTOSET(@.Timedimensionhierarchyyearmonth, CONSTRAINED), [Time dimension].[Hierarchy year-month].currentmember ) ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS