Danylo Korostil
Danylo Korostil

Reputation: 1484

To speed up the SUM and Filter functions

I wrote following MDX query:

 SUM(
        (
        Filter  
            ([Shop].[Shop ID].[Shop ID].Members,
            IsEmpty(([Time].[Calendar].CurrentMember)) 
            = false
            AND
            IsEmpty(([Time].[Calendar].CurrentMember.Lag(1))) 
            = false
            AND
            IsEmpty(([Time].[Calendar].CurrentMember.Lag(2))) 
            = false)
        ,
        [Measures].[Real weight]
        )
    )

However it works slow. I believe I can speed it up. Any ideas? I've read the following blog, but it didn't help me much. Probably I miss something important there:

http://sqlblog.com/blogs/mosha/archive/2005/02/13/performance-of-aggregating-data-from-lower-levels-in-mdx.aspx

Thanks in advance!

EDIT:

I'm sorry, find the answer here: http://sqlblog.com/blogs/mosha/archive/2008/10/22/optimizing-mdx-aggregation-functions.aspx

SUM([Shop].[Shop ID].[Shop ID].Members,
        (
        IIF(

            IsEmpty(([Time].[Calendar].CurrentMember,[Measures].[Real weight])) 
            = false
            AND
            IsEmpty(([Time].[Calendar].CurrentMember.Lag(1),[Measures].[Real weight])) 
            = false
            AND
            IsEmpty(([Time].[Calendar].CurrentMember.Lag(2),[Measures].[Real weight])) 
            = true

            ,
            [Measures].[Real weight]
            ,
            NULL)
        ))

Upvotes: 0

Views: 630

Answers (1)

Danylo Korostil
Danylo Korostil

Reputation: 1484

I'm sorry, find the answer here: http://sqlblog.com/blogs/mosha/archive/2008/10/22/optimizing-mdx-aggregation-functions.aspx

SUM([Shop].[Shop ID].[Shop ID].Members,
        (
        IIF(

            IsEmpty(([Time].[Calendar].CurrentMember,[Measures].[Real weight])) 
            = false
            AND
            IsEmpty(([Time].[Calendar].CurrentMember.Lag(1),[Measures].[Real weight])) 
            = false
            AND
            IsEmpty(([Time].[Calendar].CurrentMember.Lag(2),[Measures].[Real weight])) 
            = true

            ,
            [Measures].[Real weight]
            ,
            NULL)
        ))

Upvotes: 1

Related Questions