Showing posts with label calculated. Show all posts
Showing posts with label calculated. Show all posts

Wednesday, March 21, 2012

MeasureExpression Property - How to use

I have a cube with several MeasureGroups.

I want to provide a calculated measure "Average Sale Price" which is calculated as "Gross Revenue" / "Product Count".

Both the "Gross Revenue" and "Product Count" measures belonging to the same measure group ... "Royalty Statement". Ideally I would like the "Average Sale Price" measure also to belong to the "Royalty Statement" Measure Group also.

I am therefore trying to use a MeasureExpression calculation on a regular measure, as opposed to a Calculated Member to achieve the calculation. (or can someone advise how to make a Calculated Member appear within a specific Measure Group ?)


On the measure properties
- "AggregateFunction" is set to "Sum"
- "MeasureExpression" is set to "[Measures].[Gross Revenue] / [Measures].[Product Count]"

On deploying the cube I get ... "Error 1 Errors in the metadata manager. The 'Product Count' right operand of the measure expression of the 'Average Sale Price' measure cannot belong to the same measure group. "

Can I really not have a MeasureExpression with the numerator and denominator in the same Measure Group ?

I have futzed with things a bit including getting the cube to process by using a denominator from a different MeasureGroup, and playing with the Source object binding.

What am I missing ?

Thanks in Advance

Marcus

No. I do not think that you can use the same measure group in measure expressions. This is the new version of Lookup cube(MDX) in AS2005 with limited support for calculations except (*, /)

You can achive the same with a calculated member.

Regards

Thomas Ivarsson

|||

Marcus,

You can easily associate your calculated measure with any existing measure group. To do this, please follow these steps:

- Open your project in SQL Server Business Intelligence Development Studio & double click your cube

- In the Cube editor, go to the Calculations tab and double click your calculated member "Average Sale Price"

- In the toolbar, just right from the "Form View" and "Script View" toolbar buttons, click on the "Calculation Properties" toolbar button

- In the Calculation Properties dialog that comes up, select your calculated member "Average Sale Price" from the dropdown and set the associated measure group for it to be "Royalty Statement"

- Deploy the project and you are ready to go

Hope this helps,

Artur

|||

Thanks Artur, that helps.

If I do this, can I also assume that the Dimension Usage characteristics for that Measure Group now apply to the Calcuated Member ?

Marcus

|||

Unfortunately the answer is no. This is a common request from customers and is planned to be implemented in our next release. For Yukon, you could use the following work around: if you want to associate the new calculated member with specific dimensions, you could set the non-empty behavior for the calculated member to a measure from a measure group that intersects with those dimensions.

Hope this helps,

Artur

MeasureExpression Property - How to use

I have a cube with several MeasureGroups.

I want to provide a calculated measure "Average Sale Price" which is calculated as "Gross Revenue" / "Product Count".

Both the "Gross Revenue" and "Product Count" measures belonging to the same measure group ... "Royalty Statement". Ideally I would like the "Average Sale Price" measure also to belong to the "Royalty Statement" Measure Group also.

I am therefore trying to use a MeasureExpression calculation on a regular measure, as opposed to a Calculated Member to achieve the calculation. (or can someone advise how to make a Calculated Member appear within a specific Measure Group ?)


On the measure properties
- "AggregateFunction" is set to "Sum"
- "MeasureExpression" is set to "[Measures].[Gross Revenue] / [Measures].[Product Count]"

On deploying the cube I get ... "Error 1 Errors in the metadata manager. The 'Product Count' right operand of the measure expression of the 'Average Sale Price' measure cannot belong to the same measure group. "

Can I really not have a MeasureExpression with the numerator and denominator in the same Measure Group ?

I have futzed with things a bit including getting the cube to process by using a denominator from a different MeasureGroup, and playing with the Source object binding.

What am I missing ?

Thanks in Advance

Marcus

No. I do not think that you can use the same measure group in measure expressions. This is the new version of Lookup cube(MDX) in AS2005 with limited support for calculations except (*, /)

You can achive the same with a calculated member.

Regards

Thomas Ivarsson

|||

Marcus,

You can easily associate your calculated measure with any existing measure group. To do this, please follow these steps:

- Open your project in SQL Server Business Intelligence Development Studio & double click your cube

- In the Cube editor, go to the Calculations tab and double click your calculated member "Average Sale Price"

- In the toolbar, just right from the "Form View" and "Script View" toolbar buttons, click on the "Calculation Properties" toolbar button

- In the Calculation Properties dialog that comes up, select your calculated member "Average Sale Price" from the dropdown and set the associated measure group for it to be "Royalty Statement"

- Deploy the project and you are ready to go

Hope this helps,

Artur

|||

Thanks Artur, that helps.

If I do this, can I also assume that the Dimension Usage characteristics for that Measure Group now apply to the Calcuated Member ?

Marcus

|||

Unfortunately the answer is no. This is a common request from customers and is planned to be implemented in our next release. For Yukon, you could use the following work around: if you want to associate the new calculated member with specific dimensions, you could set the non-empty behavior for the calculated member to a measure from a measure group that intersects with those dimensions.

Hope this helps,

Artur

measure using calculated member

I have fact and 2 dimensions. i have to create a mesure using calculated member.

fact is having

fkey

ckey

monthid

hits

responses

CDIM is having

Ckey

ADateID

MonthDim is having

Monthid

MonthName

now i want a measure(XYZ) to be calculated using calculated member as Count of Ckey for AdateID = '20000101' for current member of monthdim. finally when i browse thru a cube it should display some thing like below.

Monthid XYZ

200601 1000

200602 2000

Thanks in adv

If you have a measure that is simply a row count of rows in the fact table called "Measures.FactRowCount" you can create the following calculation that would count the number of rows with AdateID = '20000101' given that you had a dimension "CDIM" with "AdateID" as an attribute:

CREATE MEMBER CURRENTCUBE MEASURES.XYZ

AS

(CDIM.AdateID.[20000101],Measures.FactRowCount),

FORMAT_STRING="#,#';

HTH,

Steve

|||

I tried this but same value is repeating for all my monthdim members. i used below query

select [Measures].[XYZ] on columns,

[Month Dim].[Month Dim Hierarchy].members on rows

from [MyCube]

--

And also I changed Expressions as below but not worked.

([Month Dim].[Month Dim].currentmember,[Cdim].[adateid].[20000101], Measures.FactRowCount)

Could you please help me

Thanks in adv

|||

Open up the cube editor and look at the "Dimension Usage" tab. Are all of your dimensions related correctly to the measure group?

- Steve

|||

Steve, they are correctly related. and i want to tell you that most of my dimensions are not directly related to fact table. they are reference thru a fact(this table is a dim for main fact) table (say FD). The measure i am creating is the distinct count of FD dimension for the selected month.

hope above info helps you to understand my problem

|||

Lets take this offline. You can email me at stevepon@.microsoft.com

It would be helpful if you could send me a copy of your project files so I could better understand the relationships.

Steve

Measure should only be calculated for certain Dimension Attributes

Hi,

I've created a Dimension - Organisation (company_name,
department_name,room_name). The primary key is Organisation_ID and I
have a Measure Room Utilization. I'd like to show this Measure only
when Room_Name is selected and with every other member of this
Dimension there should occur a 0 for Room Utilization.

It works when I create a hierachy inside the Dimension with the
following MDX statement:

CREATE MEMBER CURRENTCUBE.[MEASURES].Room_Utilization
AS
case when [Organisation].CurrentMember.Level.Ordinal = 4
then [Measures].Room_Utilization
else 0
end
VISIBLE = 1;

how can I get it going when my Organisation Dimension has the following
attributes:
company_name,
department_name,
room_name

without hierachy and I only want to calculate the Measure Room
Utilization for the room_name attribute?

Thanks!

Here is how you can do it with Analysis Services 2005

Create RoomUtilization;

(Organization.[Room Name].[Room Name].MEMBERS, Measures.RoomUtilization) = Measures.PhysicalMeasureRoomUtilization;

And, of course, you would make PhysicalMeasureRoomUtilization a hidden one.

HTH,

Mosha (http://www.mosha.com/msolap)

sql

Monday, March 19, 2012

Measure group related question

I have a cube with two fact tables, two measure groups. I also created few calculated measures.

On client side I see two measure groups and below the calculated measure.

Is there any way I can show that calculated measure in one of the measure group. It's easy for end user to see number measure and % measure both next to each other.

I hope this can be possible using MDX some how update mdx for measure group or some thing...

Thank you - Ashok

Ashok,

You can easily associate your calculated measure with any existing measure group. To do this, please follow these steps:

- Open your project in SQL Server Business Intelligence Development Studio & double click your cube

- In the Cube editor, go to the Calculations tab and double click your calculated member "Average Sale Price"

- In the toolbar, just right from the "Form View" and "Script View" toolbar buttons, click on the "Calculation Properties" toolbar button

- In the Calculation Properties dialog that comes up, select your calculated member "Average Sale Price" from the dropdown and set the associated measure group for it to be "Royalty Statement"

- Deploy the project and you are ready to go

Hope this helps,

Artur

|||

You are the man Thanks. Is there any way to move a measure from one group to another. I know If I change underline Table/View it can be done but is there any way in cube design time I can move measure from one group to another.

-Ashok

|||

Ashok, moving a measure from one measure group to another is not currently supported in AS 2005.

--Artur

measure counting distinct values from a field

How do I count the amount of distinct values from a column in a fact table as a calculated measure

Assume the primary key of my fact table is a composite of three columns (a,b,c).

How can I code a calculated measure to count every distinct value of column a, not the amount of rows in my fact table.

Any advise help would be appreciated!

All you need to do is change the measure type from Count to Distinct Count ... make sure you select Column A as your key column....

MDX: Rolling YTD

Hi,
I have been searching for a solution in MDX to create rolling
Year-to-Date calculated members.
For example:
When the current member time is June 2006, I want the total sales YTD
of last year, that
means from January 2005 till June 2005.
Thanks for any hints for a solution
RS.
ps.
My starting point was:
sum({ytd()},[Measures].[Sales])
But this formula is the sum YTD for this year. I'm searching for a
formula for the sum YTD of last year.
I've tried every combination with sum, OpeningPeriod(), lag,
ParallelPeriod().RS wrote:
> Hi,
> I have been searching for a solution in MDX to create rolling
> Year-to-Date calculated members.
>
> For example:
> When the current member time is June 2006, I want the total sales YTD
> of last year, that
> means from January 2005 till June 2005.
>
> Thanks for any hints for a solution
>
> RS.
>
> ps.
> My starting point was:
>
> sum({ytd()},[Measures].[Sales])
>
> But this formula is the sum YTD for this year. I'm searching for a
> formula for the sum YTD of last year.
>
> I've tried every combination with sum, OpeningPeriod(), lag,
> ParallelPeriod().

> I datagrep is offer the solution for most of the problems
> so visit this for ur solutions
>http://www.datagrep.com

Monday, March 12, 2012

MDX to dynamically insert calculated members into row?

I need some help writing the MDX for selecting Row members in a particular
query. Here's the background:

The query shows sales results by region and office. The row members should
be like this:

OfficeA
OfficeB
OfficeD
Region1
Region1 (SOC)
OfficeE
OfficeF
OfficeG
OfficeJ
Region2
Region2 (SOC)
World
World (SOC)

There are two things to note about this:

1. The set of offices is being filtered to only show the "active" ones (i.e.
offices which are operational - offices C, H & I have closed down)

2. The Region1, Region2 and World members are straightforward sums of their
(active) children. However, the Region1 (SOC), Region2 (SOC) and World (SOC)
members are calculated - the idea is that they represent a "Same Office
Comparison", in other words only sum the offices that were active both last
year and this year.

The dimensions used to generate the row members are:

1. Region with levels Region and Office
2. Active Office with levels Active (True/False) and SOC (True/False)

This is the MDX I used to generate the members EXCEPT for the "SOC" members:

Member [Region].[World] as
' [Region].[All Region] ' , solve_order = 1

Non Empty
{
Filter(
Hierarchize( Except( [Region].Members , [Region].[All Region] } )
, POST ) ,
[Active Office].[All Active Office].[True] > 0) ,
[Region].[World]
}
ON ROWS

Where I am stuck is generating the "SOC" members and including them in the
set of row members in the correct order. I need to do this without hard
coding any references to specific regions or offices (regions and offices
change over time).

Any ideas?

Many thanks

HI Laurence,

As you have no doubt found, it is hard to insert a calculated member in a specific location in a hierarchy. What I would suggest is to create "real" members in your dimension tables for the "(SOC)" members, but don't have any data associated with them. Then use an assignment in your MDX script to calcuate the value for these members

You could hard code a calculation something like the following:

([Region 1 (SOC)]) = Aggregate([Region].[Region].&[Region 1].Chidren,[Region].[SOC].[True])

But if it were me I think I would probably want to make the calc more generic. You could possibly add an attribute or add a "Total" member to the SOC attribute so that you could pull out just the SOC total members and then grab the children of the previous member and filter them by [SOC].[True] - or something like that Smile

|||

I do need to make the solution as generic as possible as the regions do change .... can you explain a bit more what you mean by '.... add an attribute or add a "Total" member to the SOC attribute ....'

|||

Sure. When I said "add an attribute" I was thinking that you could either change your existing [SOC] column to contain another value, so it would have "True", "False" & "Total" or you could add another column to your dimension table. Then what I would do is to add another row into your dimension table at the same level as the "Region 1" member, but called "Region 1 SOC" and tagged with a specific attribute value so that you could filter down to just these members .You would not have any facts associated with these members, they would simply be placeholders at a specific positions in the dimension. You would then use an assignment in the MDX Script to set the values for these members.

You might then be able use an assignment similar to the following (which is more psuedo code, but hopefully it will help illustrate my thought process)

Code Snippet

SCOPE [Region].[SOC].[SOC].[SOC Total] -- grab just the members tagged as "SOC Total"

-- i'm not clear on your exact structures and logic, but assuming

-- that the "SOC total" members are ordered after the real region totals,

-- the code below grabs the real region's children and adds them up,

-- filtering on only those members where [SOC] is true.

this = aggregate({[Region].[Region].[Region].Prevmember.children

, [Region].[SOC].[SOC].&{True]})

END SCOPE;

|||

Ah-ha, I think I got it! I will try it out, thanks very much.

MDX to aggregate measure over specific dimensions

Hi,

I'm trying to write a calculated member in SSAS 2005 that will only aggregate across certain dimensions. For example, say I have five dimensions: D1 - 5. I only want the member to aggregate across three of these dimensions. So in the cube browser, when I drag these three dimensions in, I get the correct aggregated value. But when I then drag dimensions four and five in, I want this value to stay the same. (The measure is currently in a measure group that uses all five dimensions).

I was thinking that the solution would be to have an MDX expression of the form

([Measures].[Measure],
[D1].CurrentMember,
[D2].CurrentMember,
[D3].CurrentMember,
[D4].[(All)],
[D5].[(All)])

but I would prefer not to have to list all dimensions and their hierarchies, and have to remember to add to this list if I add a dimension in the future. In SSAS 2000 I had a lookup cube that only contained the dimensions I wanted to slice by.

My other solution was to create a named query on the fact table that this measure is currently in, create a measure group on that, and then set up the dimension usage so that only the dimensions I want to slice by are referenced. However, I'm thinking that there must be a better solution, probably using some MDX that I don't know about!

Thanks in advance.
James

Take a look at the MDX Root function. Here's an example of something that might work for you using Adventure Works:

with member measures.rootdemo as (
root([Date].[Calendar Year].currentmember),
root([Product].[Category].currentmember),
root([Customer]),
[Measures].[Internet Sales Amount]
)
select
[Date].[Calendar Year].[Calendar Year].members
*
[Date].[Calendar Semester of Year].[Calendar Semester of Year].members
*
[Customer].[Country].[Country].members
on 0,
[Product].[Category].[Category].members
on 1
from [Adventure Works]
where(measures.rootdemo)

You still need to list all the dimensions but at least you don't need to list the hierarchies. Watch out for this 'feature' of the function, though, which occurs when more than one member from a hierarchy is in scope:

with member measures.rootdemo as (
root([Date].[Calendar Year].currentmember),
root([Product].[Category].currentmember),
root([Customer]),
[Measures].[Internet Sales Amount]
)
select
[Date].[Calendar Year].[Calendar Year].members
*
[Date].[Calendar Semester of Year].[Calendar Semester of Year].members
on 0,
[Product].[Category].[Category].members
on 1
from [Adventure Works]
where(measures.rootdemo,{[Customer].[Country].&[Australia],[Customer].[Country].&[United Kingdom]})

HTH,

Chris

|||
Hi Chris, many thanks for your reply.

This indeed worked. Going back to my previous example, I created a calculated member as:

(Root([D4]),
Root([D5]),
[Measures].[Measure])

and the measure is only sliced by dimensions D1, D2 and D3.

Thanks for your help!

James
|||

Another approach to this problem is to put these measures into dedicated measure group which excludes dimensions D4 and D5 - then you will get the aggregates you need without calculated members. Of course, if you sometimes do need detailed information over them, then the approach with calculated member is the right one.

One more note - you don't have to use Root() function if all the attributes in your dimensions are aggregatable. You will get better performance if you simply use

([D4].[All], [D5].[All], [Measures].[Measure])

|||
Hi, yes I thought those were my two options.

I don't want to create another measure group as I'll have duplicate measures and the table with this measure in is large (it's a requirement in our system to keep processing time to a minimum). I was hoping that there would be a solution where I didn't have to list every dimension I wanted to remove from the slice (and remember to add to the list if I add dimensions in the future), but at least I have a solution!

Many thanks for your help.
James

MDX Sumproduct and excel functions

Hi
Has anyone used SUMPRODUCT in a calculated member in analysis services?
Apparantly, according to MS documentation, its possible, but I can see
nothing in the books online - or on the web.
I am using the syntax below, which I would have thought would have worked.
SUMPRODUCT({[Accounts].&[123],[Accounts].&[456]},{
[Accounts].&[111],[Accounts].&[321]})
So does anyone know how to use SUMPRODUCT with AS?
Thank you for your help
JeremySince the arguments to SumProduct() are arrays, use the MDX SetToArray()
function to generate them. The second argument to SetToArray() is the
numerical value to use:
[vbcol=seagreen]
SUMPRODUCT(
SetToArray({[Accounts].&[123],[Accounts].&[456]},
[Measures].[Sales]),
SetToArray({[Accounts].&[111],[Accounts].&[321]},
[Measures].[Sales]))[vbcol=seagreen]
From SQL Server BOL>>
SetToArray
Converts one or more sets to an array for use in a user-defined
function.
Syntax
SetToArray(Set[, Set...][, Numeric Expression])
Remarks
This function converts one or more sets to an array for use in a
user-defined function. The number of dimensions in the resulting array
is the same as the number of sets specified.
The optional numeric expression can be used to provide the values in the
array cells. If omitted, the default value of the set member is used for
the array cell value.
..[vbcol=seagreen]
- Deepak
Deepak Puri
Microsoft MVP - SQL Server
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!

Friday, March 9, 2012

MDX Question - Counting members in a Dimension with a "dateCreated" attirbute

Hello,

I'm fairly new to MDX and would like to add a calculated member:

In a dimension called DimCustomers I have a field called dateJoined which specifies when. Customers have the ability to create comments.

I have created a Fact table called FactComments, which has a id, customerid, timeid

What I would like is create a calculated member which uses the dateJoined field as a way to accumulate how many members had joined at given time.

e.g.

2005 - commentCount - memeberCountat2005 - comments/member-ratio
2006 - commentCount - memberCountin2006 - comments/member-ratio

The question is, is this possible with MDX or do i have to look at the data transferred to the DW and create a field called memberCount (or something like that... )

hope anyone can help.The PeriodsToDate MDX function seems like it would work for your scenario.

MDX Question

I have a cube that I have to calculate a 100 Weight for each Measure. Currently I have created Calculated Members to the tune of what you see below:

CREATEMEMBERCURRENTCUBE.[MEASURES].[AccrualCostCWT]

AS (IIF(([Measures].[Accrual Cost]/[Measures].[Lbs]) = 0, 0,([Measures].[Accrual Cost]/[Measures].[Lbs])*100)),

FORMAT_STRING = "#,#.00",

NON_EMPTY_BEHAVIOR = { [Lbs] },

VISIBLE = 1;

CREATEMEMBERCURRENTCUBE.[MEASURES].[BrokerCostCWT]

AS (IIF(([Measures].[Broker Cost]/[Measures].[Lbs]) = 0, 0, ([Measures].[Broker Cost]/[Measures].[Lbs])*100)),

FORMAT_STRING = "#,#.00",

NON_EMPTY_BEHAVIOR = { [Lbs] },

VISIBLE = 1;

What I would like to do is create an MDX Statement that will calculate the 100 Weight (CWT) for each measure and post it next to the measure. I am sure that there is a way to do this but I am not good enough at MDX to determine what I need to do.

This is running on SQL Server 2005 service pack 2 with the latest critical updates.

Sorry, but I don't understand the "post it next to the measure" part? You just want to cells next to each other in the cell set returned by a query?

Thanks,
Bryan

|||

Thanks for wanting clarification. Here is what I am looking for.

I have a measure with a dollar amount such as accrualCost, brokerCost, etc. (20 Columns like this)

I also have a measure called LBS, I need a way to do the CWT without creating a number of Members. If I could just have one member to work this it would be great.

I would like to see it like either of the following ways.

Amount CWT accrualCost 48,247 3.7 brokerCost 29,297 4.2 accrualCost brokerCost Amount 48,247 29,297 CWT 3.7 4.2

Let me know if you need further details.

Thanks,

Scott

|||

I think I'm starting to see where you're going with this. Let me ask, where is the Amount measure coming from? When you say "Amount" are you actually referring the value of whatever measure you are referencing?

B.

MDX Question

I have a cube that I have to calculate a 100 Weight for each Measure. Currently I have created Calculated Members to the tune of what you see below:

CREATE MEMBER CURRENTCUBE.[MEASURES].[AccrualCostCWT]

AS (IIF(([Measures].[Accrual Cost]/[Measures].[Lbs]) = 0, 0,([Measures].[Accrual Cost]/[Measures].[Lbs])*100)),

FORMAT_STRING = "#,#.00",

NON_EMPTY_BEHAVIOR = { [Lbs] },

VISIBLE = 1;

CREATE MEMBER CURRENTCUBE.[MEASURES].[BrokerCostCWT]

AS (IIF(([Measures].[Broker Cost]/[Measures].[Lbs]) = 0, 0, ([Measures].[Broker Cost]/[Measures].[Lbs])*100)),

FORMAT_STRING = "#,#.00",

NON_EMPTY_BEHAVIOR = { [Lbs] },

VISIBLE = 1;

What I would like to do is create an MDX Statement that will calculate the 100 Weight (CWT) for each measure and post it next to the measure. I am sure that there is a way to do this but I am not good enough at MDX to determine what I need to do.

This is running on SQL Server 2005 service pack 2 with the latest critical updates.

Sorry, but I don't understand the "post it next to the measure" part? You just want to cells next to each other in the cell set returned by a query?

Thanks,
Bryan

|||

Thanks for wanting clarification. Here is what I am looking for.

I have a measure with a dollar amount such as accrualCost, brokerCost, etc. (20 Columns like this)

I also have a measure called LBS, I need a way to do the CWT without creating a number of Members. If I could just have one member to work this it would be great.

I would like to see it like either of the following ways.

Amount CWT accrualCost 48,247 3.7 brokerCost 29,297 4.2 accrualCost brokerCost Amount 48,247 29,297 CWT 3.7 4.2

Let me know if you need further details.

Thanks,

Scott

|||

I think I'm starting to see where you're going with this. Let me ask, where is the Amount measure coming from? When you say "Amount" are you actually referring the value of whatever measure you are referencing?

B.

Saturday, February 25, 2012

MDX performance on calculated measure

Hi,

i have two problems with the following mdx statement:

CALCULATE;

create member [Logistik_TakteReklaRedressen].[MEASURES].[delivery quantity] as null;

scope ([MEASURES].[delivery quantity]);

this = Sum([EVT Date].[HierWeek].currentMember.Children, [MEASURES].[delivery quantity]);

/*Non_Empty_Behavior(This) = {[MEASURES].[lfmenge1],[MEASURES].[lfmenge]};*/

end scope;

scope ([MEASURES].[delivery quantity], [EVT Date].[Week].[Week].Members);

this = Iif( Not (IsEmpty([MEASURES].[lfmenge1]) AND IsEmpty([MEASURES].[lfmenge])),

Aggregate(PeriodsToDate([EVT Date].[Week].[(All)], [EVT Date].[Week].currentMember), [MEASURES].[lfmenge1]) + [MEASURES].[lfmenge],

null);

/*Non_Empty_Behavior(This) = {[MEASURES].[lfmenge1]};*/

end scope;

My primary objective is to improve performance for any query with measure delivery quantity. Can the second scope statement with iif could better coded?

With the storage of weekly delta for one part of my data (lfmenge1), i can save about 90% of data sets in the fact table. Would it be better to store any data set for performance standpoints?

The second problem is that, when I have query with a where statement on time dimension and the time dimension is not on the axis. The first scope statement work not correctly.

Sorry for my broken english.

Regards Alexander

Hi Alexander,

Could you explain the logic for this calculated measure, with examples of data - that would help in making suggestions. Also, what are the attributes and structure of the [EVT Date] dimension - and is [Week] the key attribute or lowest level?

|||

Hi,

i work for a magazine publisher. We have weekly shipping from magazines for our subscribers. The delivery take place with post or mostly with our own delivery system.
The geographic structure on it's lowest level has a dimensionality of 40000. Every week we have an avervage supply quantity about 4 million.

I want to refresh the cube every week.

I separate the data in two fact tables. In the first table are the facts from the magazines with non weekly frequency (lfmenge). In this table I store every delivery (accumulated in the lowest level over all dimensions).
In the second table I store only changes and stock at beginning from the magazines with weekly frequency (lfmenge1). So I can save 90% of storage amount.

I have a hierarchy with Year -> Week. The time dimension is build from server time with key date to the fact tables.

Weekly Magazin Non Weekly Magazin

A

B

C

D

Week 52 27.12.2006 100 200 Week 52 28.12.2006 1000 2000 Week 01 02.01.2007 Week 01 03.01.2007 -10 Week 01 04.01.2007 20 Week 02 10.01.2007 5 210 Week 02 11.01.2007 1 1900 MDX sumPeriodsToDate Cum. Week 52 100 1000

+

200 2000

=

3300 Week 01 90 1020

+

=

1110 Week 02 95 1021

+

210 1900

=

3226 2006 100 1000

+

200 2000

=

3300 2007 185 2041

+

210 1900

=

4336 All 285 3041

+

410 3900

=

7636

Regards Alexander|||

Maybe a different approach could work, where [MEASURES].[lfmenge1] is assigned cumulative values at the week level, so (assuming it is a "sum" measure) these values get rolled up to the year and "All" levels. Then [MEASURES].[delivery quantity] could simply be a sum of the 2 cube measures:

CALCULATE;

scope ([MEASURES].[lfmenge1], [EVT Date].[Week].[Week].Members);

this = Aggregate(PeriodsToDate([EVT Date].[Week].[(All)], [EVT Date].[Week].currentMember));

end scope;

create member [Logistik_TakteReklaRedressen].[MEASURES].[delivery quantity] as

[MEASURES].[lfmenge1] + [MEASURES].[lfmenge];

Monday, February 20, 2012

MDX Hierarchy help

I have two calendar hierarchies in a 2005 SSAS cube. I have to make some calculations based on the date level, but of course, my calculated measures dont work when the wrong hierarchy is chosen.

I have tried to look at the .hierarchy and hierarchy() function but am unable to really understand how they work and I haven't been terribly successful looking online for info on them.

Has anyone had a similar issue? How did you test for the current hierarchy?

Here's an Adventure Works example, when either the Calendar or Fiscal hierarchy is selected on rows:

>>

With Member [Measures].[DateHierarchy] as

Axis(1).Item(0).Item(0).Hierarchy.Name

select {[Measures].[Order Quantity],

[Measures].[DateHierarchy]} on 0,

Non Empty [Date].[Calendar].[Calendar Year] on 1

from [Adventure Works]

-

Order Quantity DateHierarchy
CY 2001 11,848 Calendar
CY 2002 60,918 Calendar
CY 2003 124,615 Calendar
CY 2004 77,395 Calendar

>>

Another approach is to test whether the current member of each hierarchy is the default member (assuming that only 1 hierarchy has been navigated).

MDX help

Hi All,

I have a calculated measure in my OLAP cube which is a distinct count of one of the keys in the Fact table. This is a semi-additive measure so I need Distinct count of the last child of this measure. How can I do this? Is there a built-in function to handle this.

I am using AS 2005.

Any help would be greatly appreciated.

Rohit

Hi Rohit. More detail here is helpful. You ask for LastChild of a measure. Unfortunately, measures don't have a hierarchy so they don't have children. This means you're probably asking for one of the following:

(1) The LastChild within a hierarchy (such as Product), and the corresponding value of your semi-additive measure (what's the name of the measure?)

OR

(2) The 'closing' value of your semi-additive measure across time.

Are you asking for one of the above options, or something else. An example would be very useful.

PGoldy

|||

Paul,

The calculated measure is MarketCount (distinct count of MarketKey). I am looking for the closing value of the measure across time.

The MarketCount is a monthly snapshot and should not be added across time.

For example, if the MarketCount is 110 in July and 120 in Aug, when the user browses the data in the cube for the months of July and August, the MarketCount should display as 120 and not as 230.

Thanks.

Rohit

|||

SSAS 2005 does have built-in support for semi-additive measures like last child, but only in the Enterprise Edition

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

If you have the standard edition you could achieve the same results through calculations in the MDX script (although the performance would not be as good as the built-in feature)

|||

I am aware of the built in function for Last Child but I need to find the Distinct Count of the Last Child of one of the Fact keys. Please refer to my previous post for further details.

Paul, any ideas?

Rohit

|||

Hi Rohit:

I'm operating on a couple of assumptions here: (1) Calendar hirrearchy has structure: AllCalendar->Year->Quarter->Month (2) The lowest level in Calendar where MarketCount is valid is Month. (3) You want to see the MarketCount for the last month in the higher selected time period (Quarter, or Year). As an example, the MarketCount value for March 2006 is 130, then the Ending_MarketCount for Q1 2006 is also 130. Here's a calculated member definition for Ending_MarketCount based on my assumptions:

(TAIL(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month]), 1).Item(0), Measures.MarketCount))

The use of TAIL(DESCENDANTS() finds the last month in the quarter if quarter is the current time level. It also finds the last month in the year if Year is the current time level, and defaults to the current month if a month is the current calendar selection.

Hope this helps.

PGoldy

|||

Sorry, I left an extra parentheses on the end of the calculated member definition. Here is the corrected definition:

(TAIL(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month]), 1).Item(0), Measures.MarketCount)

PGoldy

|||

Have you thought about what you want the users to see when the data is incomplete?

For example, if we currently only have data up to August, but the users want to see the value as at calendar quarter Q3, should they see 0, because September currently has no value? Or should the calculation display the last non empty child (August)?

Wrapping the descendants function with NonEmpty() would give you "Last Non Empty Child" behaviour, but whether you need this or not depends what your business requirements are.

eg.

(TAIL(NONEMPTY(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month])), 1).Item(0), Measures.MarketCount)

...just a thought

|||

Hi Paul,

I tried your suggestion but it did not work. I might be missing something. Let me explain my scenario in more detail.

I have the following dimensions -

DimTime - Hierarchy is Year - Quarter - Month (This dimension table has a granularity of date but I have set the granularity for this dimension in the cube to month level. Would this be a problem? I need the date for other Facts which are not part of the cube in question.)

DimMarket

DimInstrumentModel

DimTerritory (Geography)

I have an aggregate Fact Table 'FactInstallBase' which has a monthly snapshot of the instruments installed and active at various customer sites. Each customer can have one or more instruments. A few sample records in the Fact table look as follows

MarketKey InstrumentModelKey TimeKey TerritoryKey InstrumentCount

123 111 222 333 2

123 112 222 333 1

125 111 222 444 2

There is a requirement to display a count of the markets that own instruments belonging to a certain Instrument model. The users browse the cube using Excel pivot table.

I have created a calculated measure 'MarketCount' and set the aggregation for this measure to DIstinctCount of MarketKey. This works fine when the users browse only one month's data. But when the user's select multiple months like Jan-2006 and Feb-2006, this mesaure gets added for both the months. If the Distinct Market Count for Jan '06 is 110 and for Feb '06 is 120 the MarketCount is displayed as 230 (110+120). This measure is semi-additive and should not be added over time. So even if the user selects multiple months, the MarketCount measure should display as the last month's MarketCount (In this case 120). Am I doing something wrong?

Any help would be greatly appreciated.

Rohit

|||

Paul,

I changed the granularity in my Time Dimension table to Month. The hierarchy for this dimension is Year - Quarter - Month but the MDX code you sent for the calculated measure still does not work.

Rohit

MDX help

Hi All,

I have a calculated measure in my OLAP cube which is a distinct count of one of the keys in the Fact table. This is a semi-additive measure so I need Distinct count of the last child of this measure. How can I do this? Is there a built-in function to handle this.

I am using AS 2005.

Any help would be greatly appreciated.

Rohit

Hi Rohit. More detail here is helpful. You ask for LastChild of a measure. Unfortunately, measures don't have a hierarchy so they don't have children. This means you're probably asking for one of the following:

(1) The LastChild within a hierarchy (such as Product), and the corresponding value of your semi-additive measure (what's the name of the measure?)

OR

(2) The 'closing' value of your semi-additive measure across time.

Are you asking for one of the above options, or something else. An example would be very useful.

PGoldy

|||

Paul,

The calculated measure is MarketCount (distinct count of MarketKey). I am looking for the closing value of the measure across time.

The MarketCount is a monthly snapshot and should not be added across time.

For example, if the MarketCount is 110 in July and 120 in Aug, when the user browses the data in the cube for the months of July and August, the MarketCount should display as 120 and not as 230.

Thanks.

Rohit

|||

SSAS 2005 does have built-in support for semi-additive measures like last child, but only in the Enterprise Edition

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

If you have the standard edition you could achieve the same results through calculations in the MDX script (although the performance would not be as good as the built-in feature)

|||

I am aware of the built in function for Last Child but I need to find the Distinct Count of the Last Child of one of the Fact keys. Please refer to my previous post for further details.

Paul, any ideas?

Rohit

|||

Hi Rohit:

I'm operating on a couple of assumptions here: (1) Calendar hirrearchy has structure: AllCalendar->Year->Quarter->Month (2) The lowest level in Calendar where MarketCount is valid is Month. (3) You want to see the MarketCount for the last month in the higher selected time period (Quarter, or Year). As an example, the MarketCount value for March 2006 is 130, then the Ending_MarketCount for Q1 2006 is also 130. Here's a calculated member definition for Ending_MarketCount based on my assumptions:

(TAIL(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month]), 1).Item(0), Measures.MarketCount))

The use of TAIL(DESCENDANTS() finds the last month in the quarter if quarter is the current time level. It also finds the last month in the year if Year is the current time level, and defaults to the current month if a month is the current calendar selection.

Hope this helps.

PGoldy

|||

Sorry, I left an extra parentheses on the end of the calculated member definition. Here is the corrected definition:

(TAIL(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month]), 1).Item(0), Measures.MarketCount)

PGoldy

|||

Have you thought about what you want the users to see when the data is incomplete?

For example, if we currently only have data up to August, but the users want to see the value as at calendar quarter Q3, should they see 0, because September currently has no value? Or should the calculation display the last non empty child (August)?

Wrapping the descendants function with NonEmpty() would give you "Last Non Empty Child" behaviour, but whether you need this or not depends what your business requirements are.

eg.

(TAIL(NONEMPTY(DESCENDANTS(Calendars.Calendars.CurrentMember, [Calendars].[Calendars].[Month])), 1).Item(0), Measures.MarketCount)

...just a thought

|||

Hi Paul,

I tried your suggestion but it did not work. I might be missing something. Let me explain my scenario in more detail.

I have the following dimensions -

DimTime - Hierarchy is Year - Quarter - Month (This dimension table has a granularity of date but I have set the granularity for this dimension in the cube to month level. Would this be a problem? I need the date for other Facts which are not part of the cube in question.)

DimMarket

DimInstrumentModel

DimTerritory (Geography)

I have an aggregate Fact Table 'FactInstallBase' which has a monthly snapshot of the instruments installed and active at various customer sites. Each customer can have one or more instruments. A few sample records in the Fact table look as follows

MarketKey InstrumentModelKey TimeKey TerritoryKey InstrumentCount

123 111 222 333 2

123 112 222 333 1

125 111 222 444 2

There is a requirement to display a count of the markets that own instruments belonging to a certain Instrument model. The users browse the cube using Excel pivot table.

I have created a calculated measure 'MarketCount' and set the aggregation for this measure to DIstinctCount of MarketKey. This works fine when the users browse only one month's data. But when the user's select multiple months like Jan-2006 and Feb-2006, this mesaure gets added for both the months. If the Distinct Market Count for Jan '06 is 110 and for Feb '06 is 120 the MarketCount is displayed as 230 (110+120). This measure is semi-additive and should not be added over time. So even if the user selects multiple months, the MarketCount measure should display as the last month's MarketCount (In this case 120). Am I doing something wrong?

Any help would be greatly appreciated.

Rohit

|||

Paul,

I changed the granularity in my Time Dimension table to Month. The hierarchy for this dimension is Year - Quarter - Month but the MDX code you sent for the calculated measure still does not work.

Rohit