Obscure MDX Month: Recreating The Star Ratings Measure In MDX Using Excel Functions
Reposted from Chris Webb's blog with the author's permission.
I still love MDX, but I’m aware that I blog about it less and less – which is a shame, I know. Therefore I’ve decided that for the next four weeks I’m going to write about some obscure MDX topics that hopefully will make all you SSAS MD diehards out there feel less neglected… even if they don’t have much practical use.
Let’s start off with recreating my ever-popular DAX star-ratings measure in MDX. Well, not exactly pure MDX, but did you know that in MDX you can call some Excel functions (in the same way you can call some VBA functions)? It’s a really, really bad thing to do from a query performance point of view, but it does allow you to do some useful calculations that might otherwise be impossible. Here’s a query on the Adventure Works cube that uses the Excel Rept() and Unichar() functions (functions that do not exist in MDX proper) to recreate my start-ratings measure:
WITH MEMBER MEASURES.STARS AS REPT( UNICHAR(9733), CINT([Measures].[Internet Sales Amount]/10000)) + REPT( UNICHAR(9734), 10-CINT([Measures].[Internet Sales Amount]/10000)) SELECT {[Measures].[Internet Sales Amount],MEASURES.STARS} ON 0, ORDER( [Date].[Date].[Date].MEMBERS, [Measures].[Internet Sales Amount], BDESC) ON 1 FROM [Adventure Works]
Here’s the same measure used in a PivotTable:
Chris has been working with Microsoft BI tools since he started using beta 3 of OLAP Services back in the late 90s. Since then he has worked with Analysis Services in a number of roles (including three years spent with Microsoft Consulting Services) and he is now an independent consultant specialising in complex MDX, Analysis Services cube design and Analysis Services query performance problems. His company website can be found at http://www.crossjoin.co.uk and his blog can be found at http://cwebbbi.wordpress.com/ . |
Tags: mdx