0845 643 64 63

Convert MDX fields to SQL

A number of our customers have reporting systems that use both MDX and SQL, retrieving data from both OLAP and SQL Server databases. This generates the problem of converting an MDX field ([Dimension].[Hierarchy].&[Attribute]) into SQL Server field value (Attribute). The following code is a Reporting Services custom code section that will rip off the MDX and leave you with the value.

    Public Function MDXParamToSQL(Parameter As String, All As String) As String

        Dim Val As String
        Val = Parameter

        If Val.Contains(“[“) Then
            If Val.ToLower().Contains(“].[all]”) Then
                Return All
                Val = Val.Substring(1, Val.LastIndexOf(“]”) – 1)
                Val = Val.Substring(Val.LastIndexOf(“[“) + 1)
                Return Val
            End If
            Return Val
        End If

    End Function

Lets say that you have a report using an MDX dataset, if you want to call a drillthrough report based on SQL Server you will need to pass at least one attribute through as a parameter to filter the second report. If you add the code above to the custom code section, you can set the parameter value of the second report to


The second report will then just receive the member name, not the full MDX unique identifier.

2 comments on “Convert MDX fields to SQL

  1. Albert Moss on said:

    Thanks, this is cool. I’m new to SSAS and SSRS. Would you have version for passing multi-parms, an array?

  2. eduardo on said:

    How to convert Mdx for Sql server

    Preço Médio Venda

    IsEmpty([Measures].[Qtd Faturada]) Or [Measures].[Qtd Faturada] <= 0,
    ([Measures].[CA Net] – [Measures].[Nota Crédito] – [Measures].[Devolução]) / [Measures].[Qtd Faturada]


    Preco Médio Net

    IsEmpty([Measures].[Qtd Faturada]) Or [Measures].[Qtd Faturada] <= 0,
    [Measures].[CA Net Líquido] / [Measures].[Qtd Faturada]

Leave a Reply

Your email address will not be published. Required fields are marked *


371,433 Spambots Blocked by Simple Comments

HTML tags are not allowed.

Power BI Sentinel
The Frog Blog

Team Purple Frog specialise in designing and implementing Microsoft Data Analytics solutions, including Data Warehouses, Cubes, SQL Server, SSIS, ADF, SSAS, Power BI, MDX, DAX, Machine Learning and more.

This is a collection of thoughts, ramblings and ideas that we think would be useful to share.


Alex Whittles
Jeet Kainth
Jon Fletcher
Nick Edwards
Joe Billingham
Lewis Prince
Reiss McSporran
Microsoft Gold Partner

Data Platform MVP

Power BI Sentinel
Frog Blog Out