Business Intelligence Blogs

View blogs by industry experts on topics such as SSAS, SSIS, SSRS, Power BI, Performance Tuning, Azure, Big Data and much more! You can also sign up to post your own business intelligence blog.

MDX Handle Dividing by Null or 0 Gracefully

  • 22 February 2010
  • Author: DustinRyan
  • Number of views: 36247

If you ever created any calculations in your cube or in an MDX query that uses division, you've probably run into the issue of dividing by zero (0) or NULL. Dividing by 0 or NULL will show the ugly -1.#INF when browsing your cube from Excel. But being the good developer you are, you don't want your end users to see that. So in order to gracefully handle dividing by 0 or NULL, we can do the following to prevent -1.#INF from exposing its ugly face to your company's executives:


MEMBER [Measures].[NullValuePerUnit] AS Null



iif([Measures].[Production]=0 OR ISEMPTY([Measures].[Production]),[Measures].[NullValuePerUnit],

[Measures].[Usage] * 1000.0/[Measures].[Production])


By using an IIF statement, we can show NULL if our calculation attempts to divide by zero or NULL, which looks a lot better than showing -1.#INF in a spreadsheet or NaN on your report.

Rate this article:


Other posts by DustinRyan

Please login or register to post comments.