Report Portal

Defining DAX Measures In The With Clause Of An MDX Query

Reposted from Chris Webb's blog with the author's permission.

It's a little-known fact (but certainly not completely unknown - it was mentioned in Marco, Alberto and my SSAS Tabular book I think) that you can define measures using DAX in the WITH clause of an MDX query. This means you can write queries like the following against an SSAS Tabular model:

with
measure ‘Date’[Demo Calc] =
countrows(‘Date’)

select {measures.[Demo Calc]} on 0,
[Date].[Calendar Year].members on 1
from [Model]

image

The official documentation, such as it is, is here:
http://msdn.microsoft.com/en-us/library/hh758441.aspx

Unfortunately you can't use it from Excel 2013 using the new 'create calculated measure' functionality; I also talked to the nice people behind OLAP PivotTable Extensions and there are some very good reasons why they can't support this either.

What use is this then? You're only going to be able to use it in scenarios where you control the generation of the MDX on the client side, such as SSRS reports, which may not be all that often; in fact, in these situations you might be better off writing the whole query in DAX. It's only going to be useful when you need the power of MDX and DAX in the same query. For example, you might want to take advantage of DAX's superior ability to detect multiselects, but write all your other calculations in MDX. I'm clutching at straws here though! Still, it's an interesting thing to know about. Please leave a comment if you can thing of a situation where you can use it.


chris-webb

Chris has been working with Microsoft BI tools since he started using beta 3 of OLAP Services back in the late 90s. Since then he has worked with Analysis Services in a number of roles (including three years spent with Microsoft Consulting Services) and he is now an independent consultant specialising in complex MDX, Analysis Services cube design and Analysis Services query performance problems. His company website can be found at http://www.crossjoin.co.uk and his blog can be found at http://cwebbbi.wordpress.com/ .


Tags: dax, tabular

 

2007-2015 VidasSoft Systems Inc.