Skip to main content

Posts

Showing posts from June, 2010

Convert String to Valid SET Expression

Create Dynamic set and Member Value based on current Date Used function: StrToSet - To convert the String into SET Expression ----------- Script Started --------------- WITH -- current date - 84 months back because of date is available in AW till 2006 -- So we required a value of month attribute MEMBER Measures.CurrentMonth AS 'FORMAT(VBA!DateAdd("m",-84,CDate(NOW())),"yyyyMM")' -- Create a set based in string expression SET CurrentMonth AS 'StrToSet("[Order Date].[Date By Year].[Month].&["+ Measures.CurrentMonth + "]")' -- Create a member from the defined set CurrentMonth MEMBER [Order Date].[Date By Year].[CurrentMonth] AS CurrentMonth.Item(0) -- Create a measure to show the unique name of tuple Member Measures.CurrentName AS CurrentMonth.Item(0).UniqueName SELECT Measures.CurrentName ON 0 FROM Sales ----------- Script Ended --------------- Output (if Current Month is 2010 06): [Order Date].[Date By Year].[Month].&[20030...

MDX AGGREGATE FUNCTION

You can use AGGREGATE function to join the set as member. for example see the below given expression: WITH SET [TwoMonth] AS { [Order Date].[Date By Year].[Month].&[200303], [Order Date].[Date By Year].[Month].&[200304] } MEMBER [Measures].[TowMonth] AS AGGREGATE({ [Order Date].[Date By Year].[Month].&[200303], [Order Date].[Date By Year].[Month].&[200304] }) Now if you are using the Member expression you will get the aggregated value of two months of Order Quantity measures. SELECT ([Order Date].[Date By Year].[TwoMonth],[Measures].[Order Quantity]) ON 0 FROM Sales //// Output (using AWDW database) TwoMonth 9260 Verify the result, use the set [TwoMonth], you should get the same result. SELECT ([TwoMonth],[Measures].[Order Quantity]) ON 0 FROM Sales // Output: March 3860, April 5400