Share via

MDX Query latency

Manoj Shinde 21 Reputation points
2021-07-27T13:21:19.467+00:00

Hi team,

I have written a query which is taking 1 hour to run, below is sample query. Can some one tell me how to improve the performance of query and what is missing in it.

// Actual 2021
With 
Member [PnL Account].[LnS PnL hierarchy].[All].[Gross Revenue] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl5].&[PnL.LnS.50110 - Gross Revenue])

Member [PnL Account].[LnS PnL hierarchy].[All].[Gross Revenue (Excl. APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl5].&[PnL.LnS.50110 - Gross Revenue],[Is InlandServices].[InlandServices_YN].&[N])

Member [PnL Account].[LnS PnL hierarchy].[All].[Gross Revenue (APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl5].&[PnL.LnS.50110 - Gross Revenue],[Is InlandServices].[InlandServices_YN].&[Y])

Member [PnL Account].[LnS PnL hierarchy].[All].[Pass Through Income] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl5].&[PnL.LnS.50120 - Net Pass Through Income])

Member [PnL Account].[LnS PnL hierarchy].[All].[Net Revenue] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.40000 - Net Revenue])

Member [PnL Account].[LnS PnL hierarchy].[All].[Variable Cost (Excl. APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.42000 - Variable Cost],[Is InlandServices].[InlandServices_YN].&[N])

Member [PnL Account].[LnS PnL hierarchy].[All].[Variable Cost (APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.42000 - Variable Cost],[Is InlandServices].[InlandServices_YN].&[Y])

Member [PnL Account].[LnS PnL hierarchy].[All].[Variable Cost] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.42000 - Variable Cost])

Member [PnL Account].[LnS PnL hierarchy].[All].[Loss on Debtors (Excl. APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.43000 - Loss On Debtors],[Is InlandServices].[InlandServices_YN].&[N])

Member [PnL Account].[LnS PnL hierarchy].[All].[Loss on Debtors (APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.43000 - Loss On Debtors],[Is InlandServices].[InlandServices_YN].&[Y])

Member [PnL Account].[LnS PnL hierarchy].[All].[Loss on Debtors] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.43000 - Loss On Debtors])

Member [PnL Account].[LnS PnL hierarchy].[All].[Gross Profit (Excl. APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl3].&[PnL.LnS.30000 - Gross Profit],[Is InlandServices].[InlandServices_YN].&[N])

Member [PnL Account].[LnS PnL hierarchy].[All].[Gross Profit (APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl3].&[PnL.LnS.30000 - Gross Profit],[Is InlandServices].[InlandServices_YN].&[Y])

Member [PnL Account].[LnS PnL hierarchy].[All].[Gross Profit] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl3].&[PnL.LnS.30000 - Gross Profit])

Member [PnL Account].[LnS PnL hierarchy].[All].[Staff Costs] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.45100 - Staff Costs])

Member [PnL Account].[LnS PnL hierarchy].[All].[IT] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.45200 - IT])

Member [PnL Account].[LnS PnL hierarchy].[All].[Consultants and Legal] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.45500 - Consultants and Legal])

Member [PnL Account].[LnS PnL hierarchy].[All].[WH Leases Costs] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.45300 - WH Leases Costs])

Member [PnL Account].[LnS PnL hierarchy].[All].[Travel] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.45600 - Travel])

Member [PnL Account].[LnS PnL hierarchy].[All].[WH Lease Depreciation] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.45400 - WH Lease Depreciation])

Member [PnL Account].[LnS PnL hierarchy].[All].[Depreciation] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.45700 - Depreciation] + [PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.45900 - Other Depreciation])

Member [PnL Account].[LnS PnL hierarchy].[All].[Other Direct Operational Cost] As
( [PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.45800 - Other Direct Operational Expenses]
+ [PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.46990 - Other Operating Costs]
)

Member [PnL Account].[LnS PnL hierarchy].[All].[Direct Operational Expenses] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl3].&[PnL.LnS.35000 - Direct Operational Expenses])

Member [PnL Account].[LnS PnL hierarchy].[All].[Direct Operational Expenses (APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl3].&[PnL.LnS.35000 - Direct Operational Expenses],[Is InlandServices].[InlandServices_YN].&[Y])

Member [PnL Account].[LnS PnL hierarchy].[All].[Product Direct Profit (Excl. APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.20000 - Product Direct Profit],[Is InlandServices].[InlandServices_YN].&[N])

Member [PnL Account].[LnS PnL hierarchy].[All].[Product Direct Profit (APMT IS)] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.20000 - Product Direct Profit],[Is InlandServices].[InlandServices_YN].&[Y])

Member [PnL Account].[LnS PnL hierarchy].[All].[Product Direct Profit] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.20000 - Product Direct Profit])

Member [PnL Account].[LnS PnL hierarchy].[All].[Customer Service, Indirect] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.26000 - Indirect Area SG&A] *
{[Activity_Function].[Activity_Function].&[Customer Service],
[Activity_Function].[Activity_Function].&[Customer Service for 4PL],
[Activity_Function].[Activity_Function].&[Customer Service for CHB],
 [Activity_Function].[Activity_Function].&[Customer Service for CHB],  
 [Activity_Function].[Activity_Function].&[Customer Service for General LS], 
 [Activity_Function].[Activity_Function].&[Customer Service for Intermodal], 
 [Activity_Function].[Activity_Function].&[Customer Service for SCM],
 [Activity_Function].[Activity_Function].&[Customer Service for WND],
 [Activity_Function].[Activity_Function].&[Customer Service LS],
 [Activity_Function].[Activity_Function].&[Customer service OCE] } )


 Member [PnL Account].[LnS PnL hierarchy].[All].[Delivery, Indirect] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.26000 - Indirect Area SG&A]*
{[Activity_Function].[Activity_Function].&[Delivery LS for 4PL],
[Activity_Function].[Activity_Function].&[Delivery LS for CHB],
[Activity_Function].[Activity_Function].&[Delivery LS for General LS],
[Activity_Function].[Activity_Function].&[Delivery LS for SCM],
[Activity_Function].[Activity_Function].&[Delivery LS for WND]
} )

 Member [PnL Account].[LnS PnL hierarchy].[All].[Finance] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.26000 - Indirect Area SG&A],[Activity_Function].[Activity_Function].&[Finance] )

Member [PnL Account].[LnS PnL hierarchy].[All].[HR] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.26000 - Indirect Area SG&A],[Activity_Function].[Activity_Function].&[HR])

Member [PnL Account].[LnS PnL hierarchy].[All].[IT, Indirect] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.26000 - Indirect Area SG&A]*
{[Activity_Function].[Activity_Function].&[Business Intelligence],
[Activity_Function].[Activity_Function].&[Digital],
[Activity_Function].[Activity_Function].&[IT]
} )

Member [PnL Account].[LnS PnL hierarchy].[All].[Sales] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.26000 - Indirect Area SG&A],[Activity_Function].[Activity_Function].&[Sales] )

Member [PnL Account].[LnS PnL hierarchy].[All].[Indirect SG&A] As
([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.26000 - Indirect Area SG&A])

Member [PnL Account].[LnS PnL hierarchy].[All].[Others, Indirect] As
Sum([PnL Account].[LnS PnL hierarchy].[All].[Indirect SG&A]) 
- 
(
[PnL Account].[LnS PnL hierarchy].[All].[Customer Service, Indirect] + 
[PnL Account].[LnS PnL hierarchy].[All].[Delivery, Indirect] +
[PnL Account].[LnS PnL hierarchy].[All].[Finance] +
[PnL Account].[LnS PnL hierarchy].[All].[HR] +
[PnL Account].[LnS PnL hierarchy].[All].[IT, Indirect] +
[PnL Account].[LnS PnL hierarchy].[All].[Sales]
)

Member [PnL Account].[LnS PnL hierarchy].[All].[Total Cost] As
( 
[PnL Account].[LnS PnL hierarchy].[All].[Indirect SG&A] + 
[PnL Account].[LnS PnL hierarchy].[All].[Direct Operational Expenses]
)

Member [PnL Account].[LnS PnL hierarchy].[All].[Amortisation] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.27000 - Amortisation])

Member [PnL Account].[LnS PnL hierarchy].[All].[Impairments] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.29000 - Impairments])

Member [PnL Account].[LnS PnL hierarchy].[All].[Joint Ventures] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl4].&[PnL.LnS.48000 - Joint Ventures])

Member [PnL Account].[LnS PnL hierarchy].[All].[Others] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.29100 - Gains/losses on sale of assets & businesses])

Member [PnL Account].[LnS PnL hierarchy].[All].[EBIT] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl1].&[PnL.LnS.10000 - EBIT])

Member [PnL Account].[LnS PnL hierarchy].[All].[EBIT (Excl. APMT IS)] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl1].&[PnL.LnS.10000 - EBIT] * {[Is InlandServices].[InlandServices_YN].&[N]})

Member [PnL Account].[LnS PnL hierarchy].[All].[EBIT (APMT IS)] As
SUM([PnL Account].[LnS PnL hierarchy].[LnS Lvl1].&[PnL.LnS.10000 - EBIT] * {[Is InlandServices].[InlandServices_YN].&[Y]})


Member [PnL Account].[LnS PnL hierarchy].[All].[EBITA] As
( 
[PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.20000 - Product Direct Profit]+
[PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.26000 - Indirect Area SG&A]+
[PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.29000 - Impairments]+
[PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.28000 - Joint Ventures]+
[PnL Account].[LnS PnL hierarchy].[LnS Lvl2].&[PnL.LnS.29100 - Gains/losses on sale of assets & businesses]
)
Select 
Non Empty
{ [Measures].[USD] } on Axis (0),

Filter(
NonEmpty(

    {   
        (
    { 
    [PnL Account].[LnS PnL hierarchy].[All].[Gross Revenue],
    [PnL Account].[LnS PnL hierarchy].[All].[Gross Revenue (Excl. APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Gross Revenue (APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Pass Through Income],
    [PnL Account].[LnS PnL hierarchy].[All].[Net Revenue],
    [PnL Account].[LnS PnL hierarchy].[All].[Variable Cost (Excl. APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Variable Cost (APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Variable Cost],
    [PnL Account].[LnS PnL hierarchy].[All].[Loss on Debtors (Excl. APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Loss on Debtors (APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Loss on Debtors],
    [PnL Account].[LnS PnL hierarchy].[All].[Gross Profit (Excl. APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Gross Profit (APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Gross Profit],
    [PnL Account].[LnS PnL hierarchy].[All].[Staff Costs],
    [PnL Account].[LnS PnL hierarchy].[All].[IT],
    [PnL Account].[LnS PnL hierarchy].[All].[Consultants and Legal],
    [PnL Account].[LnS PnL hierarchy].[All].[WH Leases Costs],
    [PnL Account].[LnS PnL hierarchy].[All].[Travel],
    [PnL Account].[LnS PnL hierarchy].[All].[WH Lease Depreciation],
    [PnL Account].[LnS PnL hierarchy].[All].[Depreciation],
    [PnL Account].[LnS PnL hierarchy].[All].[Other Direct Operational Cost],
    [PnL Account].[LnS PnL hierarchy].[All].[Direct Operational Expenses],
    [PnL Account].[LnS PnL hierarchy].[All].[Direct Operational Expenses (APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Product Direct Profit (Excl. APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Product Direct Profit (APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[Product Direct Profit],
    [PnL Account].[LnS PnL hierarchy].[All].[Customer Service, Indirect],
    [PnL Account].[LnS PnL hierarchy].[All].[Delivery, Indirect],
    [PnL Account].[LnS PnL hierarchy].[All].[Finance],
    [PnL Account].[LnS PnL hierarchy].[All].[HR],
    [PnL Account].[LnS PnL hierarchy].[All].[IT, Indirect],
    [PnL Account].[LnS PnL hierarchy].[All].[Sales],
    [PnL Account].[LnS PnL hierarchy].[All].[Indirect SG&A],
    [PnL Account].[LnS PnL hierarchy].[All].[Others, Indirect],
    [PnL Account].[LnS PnL hierarchy].[All].[Total Cost],
    [PnL Account].[LnS PnL hierarchy].[All].[Amortisation],
    [PnL Account].[LnS PnL hierarchy].[All].[Impairments],
    [PnL Account].[LnS PnL hierarchy].[All].[Joint Ventures],
    [PnL Account].[LnS PnL hierarchy].[All].[Others],
    [PnL Account].[LnS PnL hierarchy].[All].[EBIT],
    [PnL Account].[LnS PnL hierarchy].[All].[EBIT (Excl. APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[EBIT (APMT IS)],
    [PnL Account].[LnS PnL hierarchy].[All].[EBITA]
    },  

    [Time Accounting Period].[Unique Month].Children,
    [Location].[Area].Children,
    [Product].[Product Group].Children,
    [Product].[Product Family].Children,    

    {[Product].[Product Divisions].Children
        -[Product].[Product Divisions].&[APM Terminals Inland activities]
        -[Product].[Product Divisions].&[Star Air]
        -[Product].[Product Divisions].&[Twill]
        -[Product].[Product Divisions].&[Segment other]
        },
    [Brand].[Brand].Children,
    [Product].[ByMaersk Service Model].Children,
    [Consolidated Customer].[Vertical].Children,
    [Contractual Customer Attractiveness].[Contractual Customer Attractiveness].Children
        )
    }, 
    [Measures].[USD]), 
    [Measures].[USD] <> 0)  
on Axis(1)
From [Model]
Where
[Time Accounting Period].[Year].&[2021];
SQL Server Analysis Services
SQL Server Analysis Services

A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.


Answer accepted by question author

Alexei Stoyanovsky 3,416 Reputation points
2021-07-27T17:10:31.977+00:00

There's that huge crossjoin on rows that won't be easy for the engine anyway. One thing you could try, if you can't realistically simplify it, is to at least lose the filter(nonempty) construct. Wrap your existing measures.usd with IIF(measures.usd = 0, null, measures.usd) and use this on columns instead.

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. CarrinWu-MSFT 6,891 Reputation points
    2021-07-28T02:08:55.673+00:00

    Hi @Manoj Shinde ,

    Welcome to Microsoft Q&A!

    Please refer to below blogs, hope it could help you:
    DO YOU KNOW WHY YOUR MDX QUERY IS SLOW?
    Best Practices for Performance Tuning in SSAS Cubes

    Best regards,
    Carrin


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.