Search code examples
mdx

Conditional MDX QUERY


I have something like this:

the first table is how my data looks like and the second table is how my query should show the result dimensions :

Service , Company

Measure :

Amount

there are two records (with amount) for each Service in my fact table, one for mainCompany and the other one for one of the other companies (like Service1 for MainCompany And Company1)

each company can have more than one service

each service has just 2 record and one of them is for maincompany

I want to have Amount of maincompany to display as a measure for other companies


Solution

  • My guess:

    With 
    Member [Measures].[AmountMainCompany] as
    SUM(
        [Service].[Service].[Service].Members,
        IIF(
            [Measures].[Amount] > 0,
            ([Company].[Company].[MainCompany],[Measures].[Amount]),
            Null
        )
    
    )
    
    Select 
    [Measures].[AmountMainCompany] on 0,
    Non Empty {[Company].[Company].[Company].Members - [Company].[Company].[MainCompany]} on 1
    from [MyCube]
    

    AmountMainCompany measure checks if the current service contains a Amount value. If so, it aggregates the MainCompany member Amount value.