Search code examples
sql-servert-sqlssasmdx

Convert MDX Query to SQL Query


I am not able to convert MDX Query to SQL Query. Can anyone help me find any online converter maybe, or convert the code below?. I can't find one.

As I'm new to MDX Query, I find hard time trying to convert to SQL Query and was wondering if there's some resource that does it in easier way?

WITH
SET [~ROWS_RRE Information_Reporting Period] AS
    {[RRE Information].[Reporting Period].&[7]}
SET [~ROWS_Basic Claim Info_Data Provider] AS
    {[Basic Claim Info].[Data Provider].[Data Provider].Members}
SET [~ROWS_Claim Information Detail_RRE ID] AS
    {[Claim Information Detail].[RRE ID].[RRE ID].Members}
SET [~ROWS_Claim Information Detail_RRE Name] AS
    {[Claim Information Detail].[RRE Name].[RRE Name].Members}
SET [~ROWS_RRE Information_Reporting Agent] AS
    {[RRE Information].[Reporting Agent].&[Exam Works], [RRE Information].[Reporting Agent].&[Exam Works/ASSIGNED], [RRE Information].[Reporting Agent].&[Life Care Planning Solutions, LLC], [RRE Information].[Reporting Agent].&[MIRService], [RRE Information].[Reporting Agent].&[PMSI], [RRE Information].[Reporting Agent].&[PMSI Settlement Solutions], [RRE Information].[Reporting Agent].&[UNKNOWN], [RRE Information].[Reporting Agent].&[ISO]}

SELECT
NON EMPTY CrossJoin({[Basic Claim Info].[Claim Status].&[MB Pending], [Basic Claim Info].[Claim Status].&[Deleted], [Basic Claim Info].[Claim Status].&[MB Accepted], [Basic Claim Info].[Claim Status].&[MB Error], [Basic Claim Info].[Claim Status].&[MB Rejected], [Basic Claim Info].[Claim Status].&[MB Submit], [Basic Claim Info].[Claim Status].&[Q Error], [Basic Claim Info].[Claim Status].&[Q Pending], [Basic Claim Info].[Claim Status].&[Q Submitted], [Basic Claim Info].[Claim Status].&[Stopped], [Basic Claim Info].[Claim Status].[All].UNKNOWNMEMBER, [Basic Claim Info].[Claim Status].&[Not Reportable]}, {[Measures].[Claim Count]}) ON COLUMNS,
NON EMPTY ([~ROWS_RRE Information_Reporting Period]  *  [~ROWS_Basic Claim Info_Data Provider]  *  [~ROWS_Claim Information Detail_RRE ID]  *  [~ROWS_Claim Information Detail_RRE Name]  *  [~ROWS_RRE Information_Reporting Agent]) ON ROWS
FROM [MA Reporter NG]]

Solution

  • MDX and SQL are two different languages, SQL doesn't work with OLAP and MDX doesn't work with transactional DB.

    However based on the fact the your cube (SSAS project) will have an underlying dimensional model (Star schema) in transactional db. Mostly the dimensions and facts that are in the cube have an underlying table, for each dimension and fact group. Based on this assumption, I have translated your query, however the result is just a sketch to help you figure out what to do.

    select a.[Reporting Period],b.[Data Provider],c.[RRE ID],c.[RRE Name],a.[Reporting Agent],b.[Claim Status],count(distinct f.ClaimID)
    from 
    YourFact f //This will be your fact table having keys of all the dimensions 
    inner join 
    [RRE Information] a 
    on relevantkeys //Join with fact table using this dimensions key
    inner join 
    [Basic Claim Info] b 
    on relevantkeys
    inner join 
    [Claim Information Detail] c
    on relevantkeys
    where a.[Reporting Period]=7 and a.[Reporting Agent] in (this list mentioned in ~ROWS_RRE Information_Reporting Agent)
    group by 
    a.[Reporting Period],b.[Data Provider],c.[RRE ID],c.[RRE Name],a.[Reporting Agent],b.[Claim Status]