Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting results for even years only

Tags:

iccube

ssas

mdx

MDX has a nice feature whereby I can specify a range of members:

SELECT ([Canada],[2006]:[2011]) on Rows,
      [Measures].members on Columns
FROM [Sales]

Is there a way to calculate the set of even years: {[2006], [2008], [2010]}? I am looking for a way that would work for large sets, so that listing the years manually is not an option.

like image 279
AlwaysLearning Avatar asked Dec 18 '25 17:12

AlwaysLearning


1 Answers

You can filter you function using a filter function, a declared function and MOD function (MOD returns the remainder from the division - like % in Java ) :

WITH
  FUNCTION isEven(Value _number) as Mod( Int(_number) , 2 ) = 0
SELECT
  FILTER( [Date].[Date].[Year] as t, isEven( Year( t.current.key) ) )  on 0
FROM [Cube]

If you are using this filter often you could create a FilterEven declared function once in the script (same for isEven() )

like image 52
ic3 Avatar answered Dec 21 '25 21:12

ic3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!