title: Retrieving Data Type of Measures from an MDX Query/CellSet in C#
body: <p>(I am using C# 4.0.  I am connecting to a data cube via the Microsoft.AnalysisServices.AdomdClient namespace/library.)</p>
  
  <p>If I understand correctly there is exactly one axis in an MDX SELECT statement that will contain measures; the others will be based on the other dimensions.</p>
  
  <p>My immediate task (the larger task is irrelevant, I believe) is <b>given an MDX SELECT statement</b> such that the first axis contains said measures, <b>I need to programmatically determine the data type of the all of the cells pertaining to each of the measures.</b></p>
  
  <p>One way to do this, I think, would be to use the AdomdConnection and reference the CubeDef class to obtain measure information, and match that to Cellset.Set.Tuples.Members sort of thing, but then how does one account for on-the-fly measures from using the "WITH" keyword in a SELECT?</p>
  
  <p>Another way could be to look at the Value property of Cell objects associated with a given measure from executing the SELECT statement and find a non-null Cell in the CellSet, but we're not guaranteed to find a non-null value, so this is not fail-proof.</p>
  
  <p>I've looked through a CellSet in the VS debugger and haven't found any properties that give this information.</p>
  
  <p><b>Solution:</b>
  As it turns out, it is possible for a measure to have multiple data types.  At least for measures defined with a <code>WITH</code> clause, as follows:</p>
  
  <blockquote>
    <p>WITH MEMBER [Measures].[Dud] AS CASE WHEN [Measures].[Original] > 500 THEN 'A' ELSE 0 END</p>
  </blockquote>
  
  <p>Because of this, data type information is stored in each cell, and not in some sort of measures meta data.  Subsequently, the only way to learn the schema is to assume that they're all the same type, and then traverse through the measures dimension until you find a non-null cell and then learn its type.</p>