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

MDX -- Detect if ALL is selected in a dimension and adapt measure calculations based on this

$
0
0

Dear all,

I have the mdx below.

What I am trying to achieve is the following:

I have two filters : POS and Centre the constraint is that:

A) If the user selects a POS and then selects a Centre (it's always a single selection) then I calculate an average of an existing measure based on ALL the centers in that POS.

B) If the user selects ALL in the Centers filter then I shall calculate the average of the latter measure but this time for ALL the POS

I wrote the MDX below but I cannot get it to work. I think I am missing something regarding how the "ALL" attribute works.

 If I run the code with the filter: 

[TD_Centre].[Centre].AllMembers 

I seem to get condition B. But if I run with:

[TD_Centre].[Centre].&[All]

I get zeroes for KPIValue, KPINorm (ALLFED and ALLCENTRE are for testing purposes, I use it to see what KPINorm takes as value)

Then one more case, if I choose one center (which should indeed be condition A) by using:

[TD_Centre].[Centre].&[Some Center]

It still goes into condition B.

 WITH 
   MEMBER [Measures].[KPIValue] AS
		 		[Measures].[C12 Number Rate]
   MEMBER [Measures].[KPINorm] AS
			IIF([TD_Centre].[Service Centre].CurrentMember.Parent is null,
				FORMAT (
					AVG ([TD_Centre].[POS].Members,
							 [Measures].[KPIValue])
				, "Percent")
			,
				FORMAT (
				AVG ([TD_Centre].[Centre].Members, 
						[Measures].[KPIValue])
				, "Percent")
			)
   MEMBER [Measures].[ALLFED] AS
				FORMAT (
					AVG ([TD_entre].[POS].Members,
							 [Measures].[KPIValue])
				, "Percent")
   MEMBER [Measures].[ALLCENTRE] AS
				FORMAT (
				AVG ([TD_Centre].[Centre].Members, 
						[Measures].[KPIValue])
				, "Percent")
 SELECT 
	NON EMPTY { [Measures].[KPIValue], [Measures].[KPINorm],[Measures].[ALLFED],[Measures].[ALLCENTRE] } ON COLUMNS, 
	NON EMPTY { 
		(
			[TD_UneType].[UneType].[UneType].ALLMEMBERS * 
			[TD_C10Month].[C10Month].[C10 Month].ALLMEMBERS ) 
		 } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS 
FROM ( 
	SELECT 
		( 
			{ 
				[TD_UneType].[Une Type].&[01], 
				[TD_UneType].[Une Type].&[02] 
			} 
		) ON COLUMNS 
	FROM 
		(
			SELECT (
					 { 
							[TD_Centre].[Centre].AllMembers 
					 } 
				   ) ON COLUMNS 
			FROM (
				 SELECT (
					 { 
						[TD_Centre].[POS].&[2210] 
					 } 
						) ON COLUMNS 
				 FROM (
						 SELECT (
									 { 
										[TD_C10Month].[C10Month].[C10 Month].&[385],
										[TD_C10Month].[C10Month].[C10 Month].&[386],
										[TD_C10Month].[C10Month].[C10 Month].&[387]
									 } 
								 ) ON COLUMNS 
						 FROM [MyCUBE]
				)
			)
		)
	) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, 
	FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

If I am doing this wrong could somebody show me the right direction?

Thank you so much for your time

Miloud B.


Miloud Bel.



Viewing all articles
Browse latest Browse all 2472

Trending Articles