MDX and Logarithm

I am using Analysis Services 2005 and I need to create a new measure “y”,
for which I have to take the logarithm of another calculated measure "x".

i.e. y= ln (x) (where x is another calculated measure within the cube).

In AS 2000, there is the function LOG available, and in AS 2005, it somehowrecognizesthe function but it returns an error.
Why is the LOG not working? Is there something I am doing wrong? What about LN?

I searched the web and was not able to find any info about this topic.

Does anyone know how to do this?

Thanks

[799 byte] By [BrunoStocker] at [2008-3-7]
# 1
Please write [LOG] instead of LOG in your query.

This is necessary because LOG is a reserved word in Yukon, so it has to be escaped when used to designate the logarithm function.

Hope this helps

MariusDumitru at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...
# 2
Hi Marius

I tired [LOG](10) and also [LOG]([Measures].[.....]) and it did not work (no results were displayed in the browser after processing the cube.
What am I doing wrong?

thanks, Bruno

BrunoStocker at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...
# 3

I ended up writing my own assembly to reference the .net system math type to do the dirty work. There may be a way to reference the functions in the VBMDX an EXCELMDX assemblies, but I haven't had any luck yet.

To use this, create a C# Class Library project and drop in the code below. There are more examples in the sample application AMOAdventureWorks.

Once you compile the assembly, add it to your Analysis services project as an assembly reference and deploy it to the server. Then you'll be able to use it in MDX queries directly. The syntax requires the full namespace path:


select Statistics.Statistics.Statistics.Log10( [Measures].[Parameter Value])

on columns from [samples]


//assembly code starts here...

using System;
using Microsoft.AnalysisServices;
using Microsoft.AnalysisServices.AdomdServer;
namespace Statistics
{
public sealed class Statistics
{
private Statistics()
{
}
// create a wrapper for math functions not available in SAS
public static double Log10( double nValue)
{
return Math.Log10(nValue);
}
}
}

SQLMonger66 at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...
# 4

I recall all sorts of problems using the VBA and Excel functions in AS2000. I think the final resolution was something along the lines of "Install Excel First - Then install AS", becuase then it picks up the references OK.

I don't know about 2005, but it might be a similar issue.

Hope this helps,

Richard.

RichardR at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...
# 5

Prefixing the function name with VBA seems to work:

>>

With Member [Measures].[LogOrder] as

VBA![Log]([Measures].[Order Quantity])

select {[Measures].[Order Quantity],

[Measures].[LogOrder]} on 0,

[Date].[Calendar].[Calendar Year].Members on 1

from [Adventure Works]

>>

DeepakPuri at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...
# 6
Thanks. I had the same problem and Deepak's suggestion resolved it.
centexbi at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...

SQL Server

Site Classified