Quantcast
Channel: SQL Server Analysis Services Forum
Viewing all articles
Browse latest Browse all 2472

MDX Query Performance Issue

$
0
0

Hello,

I wrote a query to bring all the clients organized by region, estate and city (Regiao, UF e Municipio, in portuguese), with the count of total clients, active clients and also the color of the status of the client.

It works, but it's taking over 40 seconds to execute (about 10k clients).

I know the best would be to get the data in slices, but due to the final date of this stage I would not be able to implement such thing.

So, I would appreciate if there's any way to get a better performance with this query:

WITH 
	MEMBER [Measures].[Last Day of Period] AS
		Tail(
			Existing [Time].[Time].[Date].members
		)
		.ITEM(0).Name
	
	MEMBER [Measures].[Last Buy of Period] AS
		Tail(
				Existing(NonEmpty([Time].[Time].[Date].Members,[Measures].[ValorNota])	
			)
		).ITEM(0).Name
		
	MEMBER [Measures].[Days Without Buy] AS
		IIF ( [Measures].[Last Buy of Period] <> null, (
			DateDiff(
				"d"
				,[Measures].[Last Buy of Period]
				,[Measures].[Last Day of Period]
			)), -1)
	
	MEMBER [Measures].[Status Color] AS
		IIF([Measures].[Days Without Buy] < 0, 'dddddd', 
			IIF ([Measures].[Days Without Buy] < 32, '00b050',
				IIF([Measures].[Days Without Buy] < 63, 'ffc000',
					'ff0000'
				)
			)
		)
		
	MEMBER [Measures].[Total Clients] AS
		Count(Distinct(Descendants([Cliente].[Locais],,leaves)))
	
	MEMBER [Measures].[Total Actived Clients] AS
		DistinctCount(Descendants([Cliente].[Locais],,leaves))
		
SELECT	
    Hierarchize (
            DrilldownLevel (
                DrilldownLevel (
                    DrilldownMember (
                        DrilldownLevel (
                            [Cliente].[Locais].[All]
                        )
                        , [Cliente].[Locais].[Regiao]
                    )
                    , [Cliente].[Locais].[UF] 
                )
                , [Cliente].[Locais].[Municipio] 
            )
        ) 
        ON ROWS 
	, 
	{ 
		[Measures].[ValorNota],
        [Measures].[Total Clients],
        [Measures].[Total Actived Clients],
		[Measures].[Status Color]
	} on COLUMNS
FROM 
	[SCA 101] 
WHERE 
({
	[Time].[Time].[Year].&[2011-01-01T00:00:00],
	[Time].[Time].[Quarter].&[2012-01-01T00:00:00],
	[Time].[Time].[Quarter].&[2012-04-01T00:00:00]
}) 

By my tests, what is really taking time is Status Color. Total clients and total actived clients are ok.


Ps.: All members listed above are actually calculated members in the cube.

Ps.2: I can not get only the clients with buys, one requirement of the project is to show the prospects.

Thanks in advance for your time.



Viewing all articles
Browse latest Browse all 2472

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>