Showing posts with label measure. Show all posts
Showing posts with label measure. Show all posts

Monday, March 19, 2012

AggregationType.None - how should it work?

There is measure with the AggregationType None.

A cell with this measure is not empty only if coordinates in all dimensions are leaf. It's OK.

If the cube has fact dimension and for it dimension a leaf meber is selected, then it is clear, that cell values are build from only one fact table row. But AS doesn't realise it. Why? Is it a bug or it is by design?

My guess is that it is by design. I believe that the dimensions are treated equally with respect to the aggregation functions - hence all dimensions would have to be at the leaf level in order for a value to be returned for a measure that has aggregation function set to "None".

This does raise another question, however. What if the leaf level of the cube (measure group) is at a higher granularity than the fact table? How would the measure from the fact table aggregate up to this higher level of granularity, if the aggregation function is set to "None". I guess it is done with the sum function, but I have not tested this.

|||

"What if the leaf level of the cube (measure group) is at a higher granularity than the fact table?"

Then you have the SUM, as you guess :-)

And I think it is a bug or it was bad designed.
IMHO, the actual behavior of the AggregationType.None is unusable.

Could anybody controvert my opinion? What for nice solution can we build with actual implementation of AggregationType.None?


|||

Here are my observations from a previous post - but didn't yet receive confirmation from MS:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=616033&SiteID=1

>>

Deepak Puri

MVP

Posts 434

Answer Re: AggregateFunction -- Does "None" Work?

UnMark as answer
Edit Post | Delete Post(s) | Split Posts | Lock Post

Hi Dave,

The "None" aggregations seems to return a value if there's only a single fact record at that leaf of the measure group (SP1). I seem to recall back in the days of RTM that, if there were multiple fact records at a leaf, their "Sum" was returned, rather than null. However, this no longer worked when a fact dimension was configured.

Hopefully, someone from MS can corroborate this behavior - maybe it's by design?

>>

Aggregation problem

Hi

We have a fact table contains 5 dimension keys and one measure.The measure is having value as 1for all records and it will always be 1.Total records in this fact table are 2316.

we processed cube successfully.

Problem : While viewing data in cube browser the measure count is aggregating.We want all the records for the measure is 1. But its showing aggregate values as 1, 2 6..

Thanks

karumuru

Try connecting from Excel or some other tools you have, to the cube.

Also, If you are using the default measure " Fact Count", it will aggregate, as it is a Count.

You can specify another measure and fill it with value 1 (this is just for testing, this is not a good practice), and specify the aggregateFunction property of the measure to DistinctCount.

(I hope you are aware of the Factless fact table concept)

Regards,

Jiju

|||

Jiju

yes, Our one measure is a factless fact and had value 1. This measure aggregation property we set to distinct count and count tried all. but its aggregating and we could not get 2316 rows

Thanks

Sridhar K

Sunday, March 11, 2012

Aggregation of Calculated members of form: MEASURE op ATTRIBUTE VALUE

hi there. i do not understand how to use an attribute in a calculation. In the query below, I'm trying to say:

for all members of the date.calendar hierarchy, show me the sum of (sales amount fact * dealer price attribute for the product sold)

with

member [measures].[fact times attribute]

as cdbl([Measures].[Sales Amount]) * cdbl([Product].[Dealer Price].CurrentMember.memberValue)

select [measures].[fact times attribute] oncolumns,

[Date].[Calendar].allmembersonrows

from [Adventure Works]

where [Geography].[City].&[Beaverton]&[OR]

this gives a type mismatch error complaining that "All Products" cannot be cast to double. But I don't understand how to force the calculation to occur at the lowest level and for aggregation to be done subsequently.

Product is currently at the "All Product" member. What you are actually wanting to do is get the price for each product and multiply that by the sales of that product and then aggregate (i'll assume sum) those values. That query looks like the one below. (Actually, the one below is kinduva shortcut to the solution. Instead of going to the individual product, I just went to the product price. If two products have the same price, the query kinda says that we treat them the same. Nit-picky, I know.)

Good luck.

Code Snippet

withmember [measures].[fact times attribute] as

SUM([Product].[Dealer Price].[Dealer Price].Members,

[Measures].[Sales Amount])

select [measures].[fact times attribute] oncolumns,

NONEMPTY [Date].[Calendar].allmembersonrows

from [Adventure Works]

where ([Geography].[City].&[Beaverton]&[OR])

;

|||Dear Bryan,

Thanks for your pointers. I actually work in hong kong so were ~12 hours ahead of you. I'm checking this from home and so can't test it. but i'm reviewing it now, because I'd love to get this right for work tomorrow.

Looking at your solution, one thing I find very conceptually troubling:

>>I don't see a multiplication sign anywhere!!!!<<

So at the very point where I would imagine attribute and fact really connect, the code is silent! Also when you refer to a shortcut and being nitpicky, that is all just going straight over my head - my knowledge of mdx (rather like my knowledge of cantonese Wink just isn't evolved enough to understand the subtleties here. I can just about order lunch with a lot of gesticulation but that's it.

i will of course kick the tires on this tomorrow when I get into work. But [embarrassingly] I've been trying to figure out what the missing link is here for almost 3 days without success! Would you mind just leaving a working "best practice" solution for me? I feel like I sound like a lazy person - I'm not, I just don't grock this yet and its driving me nuts.

Yours,

John G.
|||

Sorry about that. I was pushing to get the code assembled and totally dropped that one critical part of the code. Try this one. I use the CurrentMember of the Dealer Price to get to the value.

Code Snippet

withmember [measures].[fact times attribute] as

SUM(

[Product].[Dealer Price].[Dealer Price].Members,

[Measures].[Sales Amount]*[Product].[Dealer Price].CurrentMember.MemberValue

)

select [measures].[fact times attribute] on columns,

NON EMPTY [Date].[Calendar].allmembers on rows

from [Adventure Works]

where ([Geography].[City].&[Beaverton]&[OR])

;

|||

Jo,

Try to use named calculations in the datasourceview of your factTable... it would be a better performance, because you only run the formulas once when the cube is processing.

Regards!

|||

ok it works fine - THANKS!

I also tried this which returns the same results - is it logically identical?

with

member [measures].[fact times attribute]

asSUM([Product].[Product].[Product].Members,

[Measures].[Sales Amount]*[Product].[Dealer Price].CurrentMember.MemberValue

)

select {[measures].[fact times attribute]} oncolumns,

NONEMPTY [Date].[Calendar].allmembersonrows

from [Adventure Works]

where ([Geography].[City].&[Beaverton]&[OR])

i'm not sure if you'd have the patience of a saint to wade through what follows, but I'm trying to understand the execution of the query. Would you mind critiquing the below, or if it's easier for you just describe the above query in pseudo code for dummies Wink

For my general understanding when you refer to [Product].[Dealer Price].CurrentMember.MemberValue,

what is the context of the CurrentMember? Is it:

1. The current member in the context of traversing the set of members of the product hierarchy as defined by the set argument passed to the SUM function.

or 2. the currentmember in some wider context of the query (actually I'm not sure if that makes sense, so I'll go with answer 1).

Assuming 1. above, then I would interpret the query as follows:

1. slice by beaverton

2. iterate through all members of the date hierarchy.

3. for each sales fact within the intersection of beaverton and the current date, calculate [fact times attribute] as follows:

a) for each member of the product hierarchy ...

i) ... extract the tuple set defined by the intersection of that product within the current region [for many product members this will be a null set]

ii) for that set of tuples, sum up (sales amount * dealer price).

iii) keep running total of that sum, and the final total will be your result of the current date member.

|||

thanks - this did occur to me, since as i understand it calculated members (even cube scoped ones) are calculated at runtime not at processing time, correct?

however, in my real calculation I'm using another calculated member which doesn't exist in the underlying table so this makes it tricky.

Would you say that in general, one should strive to do as much data cleaning / preparation / precalculation as possible outside the cube, and then just leave the cube to prepare aggregations and pure analysis calculations that are hard to do outside of mdx?

|||Yeah joGo, I'm with you! If you have other calculated members that you cannot replace for named calculation, so you are right...|||

Your code is logically similar and should produce the same result. You may want to test for performance differences, but the only way I can imagine a performance difference would exist would be under a very particular situation I suspect does not exist in the cube. (In other words, they probably have the same performance so don't sweat it.)

Regarding the CURRENTMEMBER question, you have to keep in mind context at all times. In the SUM function, you generate a set. That set definition is in the context of the cube as a whole. If I want to limit that context based on my slicer (WHERE clause), I can use the EXISTING keyword in the set definition.

So, now I have a set. Then, for each member in that set, I will return and/or calculate a value. That value is determined in the context of the member from the set I am currently working with. At this point, how that set came to be is unknown to me. The set has been determined and I'm just working through it blindly. I think this is what you're saying in the section at the bottom of your email.

Sorry I am being slow to respond today. The MSDN forum email seems to be jammed up a bit and I'm not getting alerts like I should.

Thanks,
Bryan

Aggregation functions in Calculated Measures displays wrong values.

Hi,

I think this calculated measure implementation is making me absent minded, so if this seems like a silly question, please ignore my behaviour but do answer to my post :-)

I will ask this question with a sample data: consider that the cube consists of School Children's names as the first dimension (school_children) and date(jan, feb....) as the second dimension. the measure (M) is the 'exam scores' of the school children.

jan feb mar
school_children M M M
--
tony 50 20 40
bony 10 40 40
mony 60 60 70

Now when i add a calculated measure where I want to display the avg marks of each. so in the calculated measures formula I add: Avg([Measures].[M]). (This is how it is in the Oracle OLAP :-))

But this does not display the average of all tony's scores in a new column M2 (calculated measure). it just displays the same values as the measure M.

so what is happening here? how to get the average then? I do not want to use an avg Aggregation. I thought that I would probably have to programmatically convert all avg functions to something like this: [Measures].[M] / count([Measure].[M]=tony or soemthing like this. not sure again.

The Avg function receives a set as a first parameter, and the measure you want to calculate the average of as a second.

The second parameter is optional, so in this case you are saying to Analysis Services: "give me the average of the measures in the current query context for the set [Measures].[M]" That is: (Measures].[M] / 1)

Since you want to calculate the avg along the time dimension, you should say:

Avg([Time],[2006].Members, [Measures].[M]).

For mor information on Avg see:

http://msdn2.microsoft.com/en-us/library/ms146067.aspx

and

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=390791&SiteID=1


AggregateFunction = None

Hi everibody.

I use a AggregateFunction = None for a measure (price for article). When I go in a client Olap, every data is Null.

Where I wrong?

Tank you

Nothing is wrong. AggregationFunction = None means the data is not aggregated and only exists on leaves of measure group. Therefore all aggregated cells are NULL. This is how None is supposed to work.|||

Sorry Mosha. For first tank you, but.....

I read that leaf of a hierarchy take value from Fact table, then the total or subtotal don't exist, but value for leaf must me exist. Instead, I never see data

Bye from Florence

Marco

|||

There is important difference between hierarchy leaves and measure group leaves. The data is loaded at measure group leaves, not at hierarchy leaves. For more details about difference between the two you can read the following: http://www.sqljunkies.com/WebLog/mosha/archive/2006/04/29/leaves.aspx

|||

Tahk you Mosha. I try to understad......

Bye Bye

Marco

AggregateFunction = None

Hi everibody.

I use a AggregateFunction = None for a measure (price for article). When I go in a client Olap, every data is Null.

Where I wrong?

Tank you

Nothing is wrong. AggregationFunction = None means the data is not aggregated and only exists on leaves of measure group. Therefore all aggregated cells are NULL. This is how None is supposed to work.|||

Sorry Mosha. For first tank you, but.....

I read that leaf of a hierarchy take value from Fact table, then the total or subtotal don't exist, but value for leaf must me exist. Instead, I never see data

Bye from Florence

Marco

|||

There is important difference between hierarchy leaves and measure group leaves. The data is loaded at measure group leaves, not at hierarchy leaves. For more details about difference between the two you can read the following: http://www.sqljunkies.com/WebLog/mosha/archive/2006/04/29/leaves.aspx

|||

Tahk you Mosha. I try to understad......

Bye Bye

Marco

Thursday, March 8, 2012

Aggregate() function not working when a measure is not specified.

Hi,

I am new to Analysis Services, having used it for less than a month. I do apologise if this problem is the result of a stupid newbie mistake, but I could really use some help.

I am totally unable to get the Aggregate() function to work unless I specify the optional measure. I have build a cube from the Adventure Works DW database, based on the internet sales fact table and related tables. I used the wizard to design the hierarchy for the time dimension.

Both of the following queries fail with the same error message:

Query 1:

WITH MEMBER [Time Aggregate Test] AS 'Aggregate({[Ship Date].[Calendar Year - Calendar Semester - Calendar Quarter - English Month Name - Day Number Of Month].[Calendar Year].&[2002].&[2].&[3].&[7]:[Ship Date].[Calendar Year - Calendar Semester - Calendar Quarter - English Month Name - Day Number Of Month].[Calendar Year].&[2003].&[1].&[2].&[5]})'

SELECT [Time Aggregate Test] ON 0,{[Measures].[Sales Amount], [Measures].[Tax Amt]} ON 1

FROM [Adventure Works DW]

Query 2

WITH MEMBER [Aggregate Test]

AS 'Aggregate({[Dim Product].[English Product Name].&[Blade],[Dim Product].[English Product Name].&[Chain]})'

SELECT [Aggregate Test] ON 0,{[Measures].[Sales Amount], [Measures].[Tax Amt]} ON 1

FROM [Adventure Works DW]

The error message is: 'The Measures hierarchy already appears on the axis0 axis. It is very important for me to be able to show the aggregate members on columns and the measures on rows if at all possible. I have checked the AggregateFunction on both measures, and it is set to Sum, which is what I want. Again, I do apologise if this is a simple newbie mistake and I would be really grateful for any help.

Since in the WITH statement you didn't specify parent hierarchy, it assumed Measures. So you ended up with same hierarchy (Measures) being used both on columns and rows. To fix you can do this:

WITH MEMBER [Dim Product].[English Product Name].[Aggregate Test]

AS 'Aggregate({[Dim Product].[English Product Name].&[Blade],[Dim Product].[English Product Name].&[Chain]})'

SELECT [Aggregate Test] ON 0,{[Measures].[Sales Amount], [Measures].[Tax Amt]} ON 1

FROM [Adventure Works DW]

|||This works perfectly. Thank you very much for your help, Mosha. Your blog has made very useful reading, by the way.

Aggregate on a Calculated Measure

I am trying to calculate aggregate on a calculate measure. See below for code. I get an error saying I cannot aggregate over calculated member in the measures dimension. I need to calculate MTD and YTD values for a calculated member. Is there any way I can do this?

Any help will be appreciated.

Thanks

Ann

Aggregate

(

PeriodsToDate

(

[Time].[Time].[Month],

[Time].[Time].CurrentMember

),

(

SUM({[Order Type].[Order Type].&[Membership Renewal Order],[Order Type].[Order Type].&[Membership Renewal with Autoship Order],[Order Type].[Order Type].&[New Membership Order],[Order Type].[Order Type].&[New Membership with Autoship Order]},[Measures].[Sale Amount]))

Try replacing the "Aggregate" function in your statement with "SUM". Since you are not attempting to aggregate a "Distinct Count" or some other semi-additive measure this should give you the result you are looking for. If you want create MTD, YTD or other period calculations that work with multiple measures your best bet is to use a "shell dimension" that will allow the creation of members using the "Aggregate" function. You can use the Business Intelligence Wizard to add time calculations, which will automate the process of creating the shell dimension for you. There are some bugs in the current version, but there is a workaround posted at the link below and SP1 includes a fix that addresses the issue.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;912136

HTH,

- Steve

Tuesday, March 6, 2012

Aggregate Function: AverageOfChildren

I am using the Aggregate Funtion: AverageOfChildren for a Measure.

I want to write a equivalent SQL query for the same. Any suggestions as to how can I ge the AverageOfChildren aggregation in a SQL query.

Thanks.

How about using the SQL Avg() aggregate function?

Aggregate Function is not allowed in Standard Server Edition

I'm trying to use None as an aggregate function on a measure but I get an error saying "Aggregate Function None is not allowed in the Standard server edition". The funny thing is that I'm running the Developer Edition.

Is the Developer Edition the same as the Standard edition? Has anyone else run into this?

This recent OLAP Newsgroup thread may help:

http://groups.google.com/group/microsoft.public.sqlserver.olap/browse_frm/thread/36855351fd3096b2/c7107957b1da7a13?#c7107957b1da7a13

>>

Aggregation function None is not allowed in Standard edition

From:Chris Webb - view profile
Date:Fri, Oct 20 2006 12:24 pm
Email: Chris Webb <onlyforpostingtonewsgro...@.crossjoin.co.uk>
Groups: microsoft.public.sqlserver.olap

Not yet rated

Rating:
show options

Reply | Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse | Find messages by this author

Hi Roger,

Have you set the Deployment Server Edition property appropriately on your project?


http://cwebbbi.spaces.live.com/blog/cns!7B84B0F2C239489A!856.entry

HTH,

Chris
--
Chris Webb, MVP
Analysis Services and MDX Consultancy: http://www.crossjoin.co.uk
Blog: http://cwebbbi.spaces.live.com/

- Hide quoted text -

"Roger" wrote:
> On my development machine, I initially installed SQL Server 2005 standard
> edition. When I attempted to add a measure with Aggregation function of None,
> I got the error message when processing - "Aggregation Function None is not
> supported in Standard Edition". Obviously I cannot install the enterprise
> edition on Win XP. But, I install the developer edition. But, when I go to
> process the cube again, I still get the same error message. Any ideas how to
> tell VS 2005 to recognize that I have the developer edition and not the
> standard edition.

Reply

3

From:Roger - view profile
Date:Fri, Oct 20 2006 12:38 pm
Email: Roger <R...@.discussions.microsoft.com>
Groups: microsoft.public.sqlserver.olap

Not yet rated

Rating:
show options

Reply | Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse | Find messages by this author

Thank god!!!!!! That worked!!!

>>

Aggregate function don't work with calculated measure.

Hi,

I can't get my AS2000 calculated measure to work with the Aggregate function.

We are using Excel as our frontend for our cubes and Excel is using the Aggregate function when the user selects multiple items for a filter dimension.

Here is the expression for my calculated measure:

Sum({Descendants([Period].[Quarter].CurrentMember, [Month])}, IIF([Currency].CurrentMember.Properties("Fixed") = "1", [Amount Fixr], [Amount Flor]) * ValidMeasure([Rate]))

I have tried different solve orders for the measure: -7000, -1, 0, 1.

When I use solve orders < 0 I get following error: "The aggregate function cannot operate on measure ..."

When I use solve orders >=0 I get an empty result set.

Any idea how to get it to work?

Thanks, Christer

One idea is to move this calculation from calculated measure to calculated member in utility dimension, and then use SOLVE_ORDER=-1.|||

I'm already using a kinf of utility dimension (my account dimension is configured with formulas) and I'm pointing to the calculated measure from these formulas. But if I understand you correctly I should move the expression from the calculated measure into to my account formula and set the solve_order to -1, correct?

Thanks, Christer

|||Yes. In AS2000 this should be enough.|||

Ok - thanks I will try it! By the way how do I set the solve_order for my formulas? I have tried to put into the formula expression <expression>, solve_order=-1, but that gives me an formula error.

Thanks

|||If you are using CustomRollup formulas, you will need to create yet another column in the dimension table and point to it CustomMemberOptions. The syntax for it is something like FORMAT_STRING='Standard', SOLVE_ORDER=-1