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

Friday, February 24, 2012

"Aggregate" of a calculated measure

Hi all,

I've got a calculated measure called [Measures].[Coverage]. I need a "report" with the following columns:

MAT = Moving Annual Total

Account Group, Coverage MAT, coverage for last MAT, and Variance.

The query should look something like this:

WITH

MEMBER

[Measures].[Coverage MAT]

AS

'AGGREGATE(LastPeriods(12, [Date].[Calendar Month Year].[Jun 2006]), [Measures].[Coverage])',

FORMAT_STRING = 'Percent'

MEMBER

[Measures].[Coverage LMAT]

AS

'AGGREGATE(LastPeriods(12, [Date].[Calendar Month Year].[Jun 2005]), [Measures].[Coverage])', //Note the 2005 year instead of 2006

FORMAT_STRING = 'Percent'

MEMBER

[Measures].[Variance]

AS

'IIF([Measures].[Coverage LMAT]=0,null,(([Measures].[Coverage MAT] - [Measures].[Coverage LMAT])/[Measures].[Coverage LMAT]))',

FORMAT_STRING = 'Percent'

SELECT

NON EMPTY {

[Account Group].[Account Group].[All].Children

} ON ROWS,

(

[Measures].[Coverage MAT],

[Measures].[Coverage LMAT],

[Measures].[Variance]

) ON COLUMNS

FROM [MyCube]

This query doesn't work because the Measures hierarchy appears more than once in the tuple and because you cannot aggregate calculated members. Any thoughts on how could I solve this issue. Thanks in advance.

It's unclear how Coverage MAT is computed from Coverage - but assuming that it's computed by averaging coverage over the last 12 months, you could substitute Avg() for Aggregate():

>>

WITH

MEMBER

[Measures].[Coverage MAT]

AS

'AVG(LastPeriods(12, [Date].[Calendar Month Year].[Jun 2006]), [Measures].[Coverage])',

FORMAT_STRING = 'Percent'

MEMBER

[Measures].[Coverage LMAT]

AS

'AVG(LastPeriods(12, [Date].[Calendar Month Year].[Jun 2005]), [Measures].[Coverage])', //Note the 2005 year instead of 2006

FORMAT_STRING = 'Percent'

MEMBER

[Measures].[Variance]

AS

'IIF([Measures].[Coverage LMAT]=0,null,(([Measures].[Coverage MAT] - [Measures].[Coverage LMAT])/[Measures].[Coverage LMAT]))',

FORMAT_STRING = 'Percent'

SELECT

NON EMPTY {

[Account Group].[Account Group].[All].Children

} ON ROWS,

{

[Measures].[Coverage MAT],

[Measures].[Coverage LMAT],

[Measures].[Variance]

} ON COLUMNS

FROM [MyCube]

|||

Hi Deepak,

I also tried to used the averages but the thing is that coverage can't be computed like this. Coverage is a calculated measure that gets the ratio of planned # calls with the actual number of calls. So if for example you have the following records:

month 1: Planned 3, Actual 0 -> Coverage 0 or 0%

month 2: Planned 3, Actual 0 -> Coverage 0 or 0%

month 3: Planned 3, Actual 9 -> Coverage 3 or 300%

Period: Planned 9 (3 + 3 + 3), Actual 9 (0 + 0 + 9) -> Coverage 1 or 100%

The problem is that the average and the real coverage is not the same (usually small difference, considerable in some cases), any ideas on how to deal with this difference?.

|||

A couple of questions then:

What is the exact definition of the Coverage calculated measure?|||

Deepak,

Coverage is the number of calls vs the number of planned calls for a certain period of time. Since you always want to follow your plan, you try that coverage is always 100%. The problem with my query is that I need to get the coverage for 2 different periods and then compare these two. With the average, we are calculating the coverage for each subperiod. Coverage is a calculated measure as I explained in the previous post, it is a very simple calculated measure (a division) but it takes care of a division by 0 (In case you have a plan for 0 calls).

I am using AS2005.

|||

One way would be apply Aggregate() separately to numerator and denominator:

MEMBER

[Measures].[Coverage MAT]

AS

AGGREGATE(LastPeriods(12, [Date].[Calendar Month Year].[Jun 2006]), [Measures].[ActualCalls])

/ AGGREGATE(LastPeriods(12, [Date].[Calendar Month Year].[Jun 2006]), [Measures].[PlannedCalls]),

FORMAT_STRING = 'Percent'

"Aggregate" function in reporting services

I have the problem of aggregating semi-additive measures correct in higher levels in a matrix control of reporting services. I use the "Microsoft SQL Server Analysis Services" data provider. I have a calculated measure saved in the AS2005 cube which looks like:

[Measure].[Net Sales (kg)] = iif( [Measures].[Sales Volume KG] = 0, 0, [Measures].[Net Sales (RLG)] / [Measures].[Sales Volume KG] )

In the matrix, I have a 4 level Product Dimension on the rows (4 groups matrix1_level1 ..... matrix1_level4) and the visibility of the groups is toggled by each upper level, so I can drill in the product dimension. I place this measure in the data part of the matrix with (sum(Fields!Net_Sales__kg_.Value)). On the leave level all values ar correct. But on each other level, I see the sum of the sublevels.

After a lot of pain researching, I found that I have to use the "aggregate" function instead of the "sum" function, because aggregate uses the aggregating which comes from the data provider and the "Microsoft SQL Server Analysis Services" data provider is able to do that. Thats all of documentation I found. I have played around with this function, but always when I use it, I get no values on all levels. I tried the "scope" parameter of the aggregat function, nothing changed.

I tried aggreagate(Fields!Net_Sales__kg_.Value, "matrix1_level1"), aggreagate(Fields!Net_Sales__kg_.Value, "SalesCube") (SalesCub is the name of my Dataset in Reporting Services I use), aggreagate(Fields!Net_Sales__kg_.Value, "matrix1") and last but not least aggregate(Fields!Net_Sales__kg_.Value), all is the same, no values.

It seems to me, that the aggragate function returns "Nothing", because than, according to the Online Help, no values will be shown. But according to some blogs and forum entries, the "Microsoft SQL Server Analysis Services (AdomdClient)" Data provider should deal with aggregate. Have I do some special entries in the "Advanced..." Settings of the data provider?

Can someone tell me, what I'm doing wrong, and did someone know a good documentation (with examples) for the aggregate function on the internet. The Help-file doc is very, very poor!!!

Thanks
Hans

I have solved it now by programming code under report properties and do my own aggregation. But I think this should be done automatically by the "aggregate" function. Does no one know a good site of documentation and what data providers can use them and how?

Thanks
Hans

|||

Can you please add some more details about your custom aggregation? I have a very similar problem and I need to work around it somehow...

Thanks,

Efi

|||

Hi Efi,

I wrote a little Function in the Code-part of the Report Properties like:

Public Function CalcLevelSum(fname as string, svkg as double, svm2 as double, sMeasure as double) as double
Dim sret as double

if fname = "AVWeight" then
sret = iif(svm2 = 0, 0, svkg * 1000 / svm2)
elseif right(fname, 3) = "kg)" then
sret = iif(svkg = 0, 0, sMeasure / svkg)
elseif right(fname, 3) = "m2)" then
sret = iif(svm2 = 0, 0, sMeasure / svm2)
else
sret = sMeasure / 1000
end if

return sret

End Function

And in the cells I changed the generated Sum-Formula to

=Code.CalcLevelSum(Parameters!SelectedMeasure.Value, Sum(Fields!Measures_Ym2SalesVolumeKG.Value), Sum(Fields!Measures_Ym2SalesVolumeM2.Value), Sum(CDbl(Fields!Measures_Ym2Amount.Value)))

With this approach, I calculate on each hierarchie level the devided values by myself. I have done a further standardisation in my cube: all per kg-values have the letters (kg) at the end of the Measure-Name, and all m2 Values (m2). So I can easily determine if the value must be devided or not. The parameters are only the sums which I need for deviding.

One necessary thing is the CDbl Casting of the measure Value. If you do not cast it with CDbl, you get an error!

Hans

"Aggregate" function in reporting services

I have the problem of aggregating semi-additive measures correct in higher levels in a matrix control of reporting services. I use the "Microsoft SQL Server Analysis Services" data provider. I have a calculated measure saved in the AS2005 cube which looks like:

[Measure].[Net Sales (kg)] = iif( [Measures].[Sales Volume KG] = 0, 0, [Measures].[Net Sales (RLG)] / [Measures].[Sales Volume KG] )

In the matrix, I have a 4 level Product Dimension on the rows (4 groups matrix1_level1 ..... matrix1_level4) and the visibility of the groups is toggled by each upper level, so I can drill in the product dimension. I place this measure in the data part of the matrix with (sum(Fields!Net_Sales__kg_.Value)). On the leave level all values ar correct. But on each other level, I see the sum of the sublevels.

After a lot of pain researching, I found that I have to use the "aggregate" function instead of the "sum" function, because aggregate uses the aggregating which comes from the data provider and the "Microsoft SQL Server Analysis Services" data provider is able to do that. Thats all of documentation I found. I have played around with this function, but always when I use it, I get no values on all levels. I tried the "scope" parameter of the aggregat function, nothing changed.

I tried aggreagate(Fields!Net_Sales__kg_.Value, "matrix1_level1"), aggreagate(Fields!Net_Sales__kg_.Value, "SalesCube") (SalesCub is the name of my Dataset in Reporting Services I use), aggreagate(Fields!Net_Sales__kg_.Value, "matrix1") and last but not least aggregate(Fields!Net_Sales__kg_.Value), all is the same, no values.

It seems to me, that the aggragate function returns "Nothing", because than, according to the Online Help, no values will be shown. But according to some blogs and forum entries, the "Microsoft SQL Server Analysis Services (AdomdClient)" Data provider should deal with aggregate. Have I do some special entries in the "Advanced..." Settings of the data provider?

Can someone tell me, what I'm doing wrong, and did someone know a good documentation (with examples) for the aggregate function on the internet. The Help-file doc is very, very poor!!!

Thanks
Hans

I have solved it now by programming code under report properties and do my own aggregation. But I think this should be done automatically by the "aggregate" function. Does no one know a good site of documentation and what data providers can use them and how?

Thanks
Hans

|||

Can you please add some more details about your custom aggregation? I have a very similar problem and I need to work around it somehow...

Thanks,

Efi

|||

Hi Efi,

I wrote a little Function in the Code-part of the Report Properties like:

Public Function CalcLevelSum(fname as string, svkg as double, svm2 as double, sMeasure as double) as double
Dim sret as double

if fname = "AVWeight" then
sret = iif(svm2 = 0, 0, svkg * 1000 / svm2)
elseif right(fname, 3) = "kg)" then
sret = iif(svkg = 0, 0, sMeasure / svkg)
elseif right(fname, 3) = "m2)" then
sret = iif(svm2 = 0, 0, sMeasure / svm2)
else
sret = sMeasure / 1000
end if

return sret

End Function

And in the cells I changed the generated Sum-Formula to

=Code.CalcLevelSum(Parameters!SelectedMeasure.Value, Sum(Fields!Measures_Ym2SalesVolumeKG.Value), Sum(Fields!Measures_Ym2SalesVolumeM2.Value), Sum(CDbl(Fields!Measures_Ym2Amount.Value)))

With this approach, I calculate on each hierarchie level the devided values by myself. I have done a further standardisation in my cube: all per kg-values have the letters (kg) at the end of the Measure-Name, and all m2 Values (m2). So I can easily determine if the value must be devided or not. The parameters are only the sums which I need for deviding.

One necessary thing is the CDbl Casting of the measure Value. If you do not cast it with CDbl, you get an error!

Hans

"Aggregate" function in reporting services

I have the problem of aggregating semi-additive measures correct in higher levels in a matrix control of reporting services. I use the "Microsoft SQL Server Analysis Services" data provider. I have a calculated measure saved in the AS2005 cube which looks like:

[Measure].[Net Sales (kg)] = iif( [Measures].[Sales Volume KG] = 0, 0, [Measures].[Net Sales (RLG)] / [Measures].[Sales Volume KG] )

In the matrix, I have a 4 level Product Dimension on the rows (4 groups matrix1_level1 ..... matrix1_level4) and the visibility of the groups is toggled by each upper level, so I can drill in the product dimension. I place this measure in the data part of the matrix with (sum(Fields!Net_Sales__kg_.Value)). On the leave level all values ar correct. But on each other level, I see the sum of the sublevels.

After a lot of pain researching, I found that I have to use the "aggregate" function instead of the "sum" function, because aggregate uses the aggregating which comes from the data provider and the "Microsoft SQL Server Analysis Services" data provider is able to do that. Thats all of documentation I found. I have played around with this function, but always when I use it, I get no values on all levels. I tried the "scope" parameter of the aggregat function, nothing changed.

I tried aggreagate(Fields!Net_Sales__kg_.Value, "matrix1_level1"), aggreagate(Fields!Net_Sales__kg_.Value, "SalesCube") (SalesCub is the name of my Dataset in Reporting Services I use), aggreagate(Fields!Net_Sales__kg_.Value, "matrix1") and last but not least aggregate(Fields!Net_Sales__kg_.Value), all is the same, no values.

It seems to me, that the aggragate function returns "Nothing", because than, according to the Online Help, no values will be shown. But according to some blogs and forum entries, the "Microsoft SQL Server Analysis Services (AdomdClient)" Data provider should deal with aggregate. Have I do some special entries in the "Advanced..." Settings of the data provider?

Can someone tell me, what I'm doing wrong, and did someone know a good documentation (with examples) for the aggregate function on the internet. The Help-file doc is very, very poor!!!

Thanks
Hans

I have solved it now by programming code under report properties and do my own aggregation. But I think this should be done automatically by the "aggregate" function. Does no one know a good site of documentation and what data providers can use them and how?

Thanks
Hans

|||

Can you please add some more details about your custom aggregation? I have a very similar problem and I need to work around it somehow...

Thanks,

Efi

|||

Hi Efi,

I wrote a little Function in the Code-part of the Report Properties like:

Public Function CalcLevelSum(fname as string, svkg as double, svm2 as double, sMeasure as double) as double
Dim sret as double

if fname = "AVWeight" then
sret = iif(svm2 = 0, 0, svkg * 1000 / svm2)
elseif right(fname, 3) = "kg)" then
sret = iif(svkg = 0, 0, sMeasure / svkg)
elseif right(fname, 3) = "m2)" then
sret = iif(svm2 = 0, 0, sMeasure / svm2)
else
sret = sMeasure / 1000
end if

return sret

End Function

And in the cells I changed the generated Sum-Formula to

=Code.CalcLevelSum(Parameters!SelectedMeasure.Value, Sum(Fields!Measures_Ym2SalesVolumeKG.Value), Sum(Fields!Measures_Ym2SalesVolumeM2.Value), Sum(CDbl(Fields!Measures_Ym2Amount.Value)))

With this approach, I calculate on each hierarchie level the devided values by myself. I have done a further standardisation in my cube: all per kg-values have the letters (kg) at the end of the Measure-Name, and all m2 Values (m2). So I can easily determine if the value must be devided or not. The parameters are only the sums which I need for deviding.

One necessary thing is the CDbl Casting of the measure Value. If you do not cast it with CDbl, you get an error!

Hans

"Aggregate" function in reporting services

I have the problem of aggregating semi-additive measures correct in higher levels in a matrix control of reporting services. I use the "Microsoft SQL Server Analysis Services" data provider. I have a calculated measure saved in the AS2005 cube which looks like:

[Measure].[Net Sales (kg)] = iif( [Measures].[Sales Volume KG] = 0, 0, [Measures].[Net Sales (RLG)] / [Measures].[Sales Volume KG] )

In the matrix, I have a 4 level Product Dimension on the rows (4 groups matrix1_level1 ..... matrix1_level4) and the visibility of the groups is toggled by each upper level, so I can drill in the product dimension. I place this measure in the data part of the matrix with (sum(Fields!Net_Sales__kg_.Value)). On the leave level all values ar correct. But on each other level, I see the sum of the sublevels.

After a lot of pain researching, I found that I have to use the "aggregate" function instead of the "sum" function, because aggregate uses the aggregating which comes from the data provider and the "Microsoft SQL Server Analysis Services" data provider is able to do that. Thats all of documentation I found. I have played around with this function, but always when I use it, I get no values on all levels. I tried the "scope" parameter of the aggregat function, nothing changed.

I tried aggreagate(Fields!Net_Sales__kg_.Value, "matrix1_level1"), aggreagate(Fields!Net_Sales__kg_.Value, "SalesCube") (SalesCub is the name of my Dataset in Reporting Services I use), aggreagate(Fields!Net_Sales__kg_.Value, "matrix1") and last but not least aggregate(Fields!Net_Sales__kg_.Value), all is the same, no values.

It seems to me, that the aggragate function returns "Nothing", because than, according to the Online Help, no values will be shown. But according to some blogs and forum entries, the "Microsoft SQL Server Analysis Services (AdomdClient)" Data provider should deal with aggregate. Have I do some special entries in the "Advanced..." Settings of the data provider?

Can someone tell me, what I'm doing wrong, and did someone know a good documentation (with examples) for the aggregate function on the internet. The Help-file doc is very, very poor!!!

Thanks
Hans

I have solved it now by programming code under report properties and do my own aggregation. But I think this should be done automatically by the "aggregate" function. Does no one know a good site of documentation and what data providers can use them and how?

Thanks
Hans

|||

Can you please add some more details about your custom aggregation? I have a very similar problem and I need to work around it somehow...

Thanks,

Efi

|||

Hi Efi,

I wrote a little Function in the Code-part of the Report Properties like:

Public Function CalcLevelSum(fname as string, svkg as double, svm2 as double, sMeasure as double) as double
Dim sret as double

if fname = "AVWeight" then
sret = iif(svm2 = 0, 0, svkg * 1000 / svm2)
elseif right(fname, 3) = "kg)" then
sret = iif(svkg = 0, 0, sMeasure / svkg)
elseif right(fname, 3) = "m2)" then
sret = iif(svm2 = 0, 0, sMeasure / svm2)
else
sret = sMeasure / 1000
end if

return sret

End Function

And in the cells I changed the generated Sum-Formula to

=Code.CalcLevelSum(Parameters!SelectedMeasure.Value, Sum(Fields!Measures_Ym2SalesVolumeKG.Value), Sum(Fields!Measures_Ym2SalesVolumeM2.Value), Sum(CDbl(Fields!Measures_Ym2Amount.Value)))

With this approach, I calculate on each hierarchie level the devided values by myself. I have done a further standardisation in my cube: all per kg-values have the letters (kg) at the end of the Measure-Name, and all m2 Values (m2). So I can easily determine if the value must be devided or not. The parameters are only the sums which I need for deviding.

One necessary thing is the CDbl Casting of the measure Value. If you do not cast it with CDbl, you get an error!

Hans

Saturday, February 11, 2012

#value in Cube Calculation

Hello all

GIven the following calculation

([Measures].[12 Month Total Sales],[Sales History].[Sales YM].[Year].lag(1))

were 12 Month Total Sales is a measure of Sale History why do I get #value for this calculation ?

Thanks for your assistance

My guess is that [Sales History].[Sales YM].[Year] is a level, and lag() only works on a member. Does this do what you want?

([Measures].[12 Month Total Sales],[Sales History].[Sales YM].currentmember.lag(1))

Chris

|||thank you

#N/A in measures - Excel 2003 client

After giving some users read access to the cube, by using a readonly role -
The [Measures] are displayed with #N/A in Excel 2003. Only users with loal administrator previledge can see measures.

Please advise.

What I encountered with AS 2005 was that Cell Security defaulted to denying access to a reader role, resulting in #N/A. So I simply entered "1" as the MDX expression for "allow reading of cube content" - not sure if this is the issue for you as well:

http://msdn2.microsoft.com/en-us/library/ms174847(SQL.90).aspx

>>

Granting Custom Access to Cell Data

After you grant a database role in Microsoft SQL Server 2005 Analysis Services (SSAS) read or read/write permissions to a cube, you have to grant to this database role the permission to view some or all cell data. Only granting cube access to a database role does not give that database role access to specific cube cells.

...

>>

|||Can you please give more details about when AS2005 by default disables cell security ? Creating cell security, even as trivial as constant 1 may have very bad effect on performance, since there are many important optimizations which are disabled in the presence of cell security...|||

Hi Mosha,

From what I can tell (based on a simple prototype AS 2005 RTM cube), cell read is disabled by default, unless "Full control (Administrator)" is selected on this page:

http://msdn2.microsoft.com/en-us/library/ms188508(SQL.90).aspx

>>

General (Role Designer) (SSAS)

>>

And that is regardless of "Enable read permissions" being checked on this page (unless "1" is entered for the "Allow reading of cube content" MDX expression):

http://msdn2.microsoft.com/en-us/library/ms177279(SQL.90).aspx

>>

Cell Data (Role Designer) (SSAS)

>>

Is there perhaps a better way to configure cell read access for a non-admin role?

|||

Dear ASMK,

Please check your cell security MDX, the measure you are viewing might be in the

denied member list. This might be helpfull.

#N/A in measures - Excel 2003 client

After giving some users read access to the cube, by using a readonly role -
The [Measures] are displayed with #N/A in Excel 2003. Only users with loal administrator previledge can see measures.

Please advise.

What I encountered with AS 2005 was that Cell Security defaulted to denying access to a reader role, resulting in #N/A. So I simply entered "1" as the MDX expression for "allow reading of cube content" - not sure if this is the issue for you as well:

http://msdn2.microsoft.com/en-us/library/ms174847(SQL.90).aspx

>>

Granting Custom Access to Cell Data

After you grant a database role in Microsoft SQL Server 2005 Analysis Services (SSAS) read or read/write permissions to a cube, you have to grant to this database role the permission to view some or all cell data. Only granting cube access to a database role does not give that database role access to specific cube cells.

...

>>

|||Can you please give more details about when AS2005 by default disables cell security ? Creating cell security, even as trivial as constant 1 may have very bad effect on performance, since there are many important optimizations which are disabled in the presence of cell security...|||

Hi Mosha,

From what I can tell (based on a simple prototype AS 2005 RTM cube), cell read is disabled by default, unless "Full control (Administrator)" is selected on this page:

http://msdn2.microsoft.com/en-us/library/ms188508(SQL.90).aspx

>>

General (Role Designer) (SSAS)

>>

And that is regardless of "Enable read permissions" being checked on this page (unless "1" is entered for the "Allow reading of cube content" MDX expression):

http://msdn2.microsoft.com/en-us/library/ms177279(SQL.90).aspx

>>

Cell Data (Role Designer) (SSAS)

>>

Is there perhaps a better way to configure cell read access for a non-admin role?

|||

Dear ASMK,

Please check your cell security MDX, the measure you are viewing might be in the

denied member list. This might be helpfull.