Last active
August 29, 2015 14:20
-
-
Save pstoellberger/fabb68d363772c021307 to your computer and use it in GitHub Desktop.
mondrian UDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For queries like: | |
select Measures.[Price Range] on columns, | |
Product.Products.Members on rows | |
from [Sales Cube] | |
..... | |
<CalculatedMember name="Price Range" formatString="#,##0.00 %" formula="PriceRange(Measures.Price)" dimension="Measures" visible="true"> | |
</CalculatedMember> | |
</Cube> | |
<UserDefinedFunction name="PriceRange"> | |
<Script language="JavaScript"> | |
function getParameterTypes() { | |
return new Array(new mondrian.olap.type.NumericType()); | |
} | |
function getReturnType(parameterTypes) { | |
return new mondrian.olap.type.StringType(); | |
} | |
function execute(evaluator, arguments) { | |
var n = arguments[0].evaluateScalar(evaluator); | |
return bucket(n); | |
} | |
function bucket(n) { | |
if (n == null || typeof n == "undefined") return null; | |
else if ( n < 0.3) return '< 0.30'; | |
else if ( n >= 0.3 && n < 0.5) return '0.30-0.49'; | |
else if ( n >= 0.5 && n < 0.8) return '0.50-0.79'; | |
else if ( n >= 0.8 && n < 1) return '0.80-0.99'; | |
else if ( n >= 1 && n < 1.3) return '1.00-1.29'; | |
else if ( n >= 1.3 && n < 1.5) return '1.30-1.49'; | |
else if ( n >= 1.5 && n < 1.8) return '1.50-1.79'; | |
else if ( n >= 1.8 && n < 2) return '1.80-1.99'; | |
else if ( n >= 2 && n < 2.5) return '2.00-2.49'; | |
else if ( n >= 2.5 && n < 3) return '2.50-2.99'; | |
else if ( n >= 3 && n < 3.5) return '3.00-3.49'; | |
else if ( n >= 3.5 && n < 4) return '3.50-3.99'; | |
else if ( n >= 4 && n < 4.5) return '4.00-4.49'; | |
else if ( n >= 4.5 && n < 5) return '4.50-4.99'; | |
else if ( n >= 5 && n < 5.5) return '5.00-5.49'; | |
else if ( n >= 5.5 && n < 6) return '5.50-5.99'; | |
else if ( n >= 6 && n < 6.5) return '6.00-6.49'; | |
else if ( n >= 6.5 && n < 7) return '6.50-6.99'; | |
else if ( n >= 7 && n < 7.5) return '7.00-7.49'; | |
else if ( n >= 7.5 && n < 8) return '7.50-7.99'; | |
else if ( n >= 8 && n < 9) return '8.00-8.99'; | |
else if ( n >= 9 && n < 10) return '9.00-9.99'; | |
else if ( n >= 10 && n < 11) return '10.00-10.99'; | |
else if ( n >= 11 && n < 12) return '11.00-11.99'; | |
else if ( n >= 12 && n < 13) return '12.00-12.99'; | |
else if ( n >= 13 && n < 14) return '13.00-13.99'; | |
else if ( n >= 14 && n < 15) return '14.00-14.99'; | |
else if ( n >= 15 && n < 16) return '15.00-15.99'; | |
else if ( n >= 16 && n < 17) return '16.00-16.99'; | |
else if ( n >= 17 && n < 18) return '17.00-17.99'; | |
else if ( n >= 18 && n < 19) return '18.00-18.99'; | |
else if ( n >= 19 && n < 20) return '19.00-19.99'; | |
else if ( n >= 20 && n < 30) return '20.00-29.99'; | |
else return '>= 30' | |
return null; | |
} | |
</Script> | |
</UserDefinedFunction> | |
</Schema> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment