0

We have a MDX query which looks like this:

WITH Member [Measures].[Z] AS (DATEADD("H",-1,[X].[Y].Member_Caption)) 
SELECT { [X].[Y].Children } ON Rows,
       { [Measures].[Z] } ON Columns
FROM ABC

It basically returns Datetime (LastRefresh).

My task is to create an MDX query that returns the following columns:

LastRefresh, Getdate(), datediff(Mins, LastRefresh, Getdate())

Its equivalent SQL query is:

select LastRefresh, getdate() as CurrentDate, datediff(Mins, LastRefresh, getdate()) as DateDifference from XYZ

How can I do the same in MDX on the Cube?

Note:

We can't create any new measures, as we are just using the Cube to get data, and don't have any kind of access to create measures etc.

Community
  • 1
  • 1
Chetan Kulkarni
  • 404
  • 4
  • 15

1 Answers1

0

GETDATE() is a SQL function, but you are writing MDX, so it is not allowed.

If you are using Microsoft SSAS then VBA is allowed within MDX, and you can use Now() to return the current date and time.

Use the VBA format of DateDiff (not the SQL version!) and you can do the calculation that way. You probably need CDate() to turn the string value of a member name into a date object for VBA to use. Such as...

DateDiff("d", CDate([X].[Y].MemberName), Now())
Magnus Smith
  • 5,895
  • 7
  • 43
  • 64