<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DMV Query &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/dmv-query/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 10 Jul 2018 10:39:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>DMV Query &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Find Datatype Of Each Measures In SSAS MDX Queries</title>
		<link>https://sibeeshpassion.com/find-datatype-of-each-measures-in-ssas-mdx-queries/</link>
					<comments>https://sibeeshpassion.com/find-datatype-of-each-measures-in-ssas-mdx-queries/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 22 Feb 2016 00:00:20 +0000</pubDate>
				<category><![CDATA[MDX Query]]></category>
		<category><![CDATA[SSAS]]></category>
		<category><![CDATA[Datatype Of Each Measures]]></category>
		<category><![CDATA[DMV Query]]></category>
		<category><![CDATA[MDX]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11226</guid>

					<description><![CDATA[In this post we will see how we can get the datatype of each measures we use in our SSAS MDX Queries. This post may be helpful if you are working with SSAS cubes especially you need to work with the data you gets from the cubes like formatting the data, assigning the data as grid data source or formulate the data to any other form. I have got a requirement to show the cube data as a grid, So I was needed to know the types of each measures user selects so that I can assign the grid column [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will see how we can get the datatype of each measures we use in our <a href="http://sibeeshpassion.com/category/ssas/" target="_blank">SSAS </a><a href="http://sibeeshpassion.com/category/microsoft-adomd/mdx-query/" target="_blank">MDX Queries</a>. This post may be helpful if you are working with SSAS cubes especially you need to work with the data you gets from the cubes like formatting the data, assigning the data as grid data source or formulate the data to any other form. I have got a requirement to show the cube data as a grid, So I was needed to know the types of each measures user selects so that I can assign the grid column types accordingly. There are few many ways we can find the types of measures, here I am going to discuss that with you. I hope you will like this. </p>
<p><strong>Background</strong></p>
<p>I had gone through this requirement and I could do this in time with the help of Mr.GregGalloway (Stack overflow user). You can find my question <a href="http://stackoverflow.com/questions/34528747/find-data-type-of-measures-in-cube-using-mdx-queries" target="_blank">here </a>in stack overflow. </p>
<p>If your cube has data with the types of string and numbers alone, finding the types will be too easy. Now before going through the processes listed in this article, if you don&#8217;t have only string and numbers as the types in the cube, this <a href="http://stackoverflow.com/questions/9951314/retrieving-data-type-of-measures-from-an-mdx-query-cellset-in-c-sharp" target="_blank">post </a>will definitely help you.</p>
<blockquote><p>If you are looking for some sample stored procedures that will help you with your development with your analysis services, you can always see it <a href="https://asstoredprocedures.codeplex.com/" target="_blank">here: ASSP &#8211; Analysis Services Stored Procedure Project</a>.
</p></blockquote>
<p><strong>Using the code</strong></p>
<p>Here we are going to create a function which accepts server name, database name, and the measure name collection in which we need to find out what type it is. The core part of this function will be a DMV query which we can run against our SSAS cube. The query will be as follows. </p>
<p>[sql]<br />
select [CATALOG_NAME],[CUBE_NAME],MEASURE_NAME, DATA_TYPE,EXPRESSION,MEASURE_IS_VISIBLE,MEASUREGROUP_NAME,MEASURE_DISPLAY_FOLDER,DEFAULT_FORMAT_STRING  from $system.mdschema_measures<br />
[/sql]</p>
<p>Now before going further, please make sure that you have included AnalysisServices Adomd Client.</p>
<p>[csharp]<br />
using Microsoft.AnalysisServices.AdomdClient;<br />
[/csharp]</p>
<p>Now we will create the function which will give you the data about the datatypes of your measures. </p>
<p>[csharp]<br />
#region Return the data types of measures<br />
        /// &lt;summary&gt;<br />
        /// FindMeasureDataTypes-Find the measure type whetehr it is a currency or a percentage or a number<br />
        /// &lt;/summary&gt;<br />
        /// &lt;param name=&quot;serverName&quot;&gt;&lt;/param&gt;<br />
        /// &lt;param name=&quot;databaseName&quot;&gt;&lt;/param&gt;<br />
        /// &lt;param name=&quot;myMeasureCollection&quot;&gt;&lt;/param&gt;<br />
        public DataTable FindMeasureDataTypes(string serverName, string databaseName, string myMeasureCollection)<br />
        {</p>
<p>            try<br />
            {<br />
                string res = string.Empty;<br />
                List&lt;string&gt; myMeasures = new List&lt;string&gt;();</p>
<p>                //Buiding the connection string start<br />
                StringBuilder sbConnectionString = new StringBuilder();<br />
                sbConnectionString.Append(&quot;Provider=MSOLAP;data source=&quot;);<br />
                sbConnectionString.Append(serverName + &quot;;initial catalog=&quot; + databaseName + &quot;;Integrated Security=SSPI;Persist Security Info=False;&quot;);<br />
                //Buiding the connection string start</p>
<p>                AdomdConnection conn = new AdomdConnection(sbConnectionString.ToString());<br />
                myMeasures = myMeasureCollection.Split(new string[] { &quot;||&quot; }, StringSplitOptions.None).ToList();</p>
<p>                for (int i = 0; i &lt; myMeasures.Count; i++)<br />
                {<br />
                    //Format the measure name<br />
                    if (i == 0)<br />
                        res += &quot;MEASURE_NAME =&#8217;&quot; + myMeasures[i].Replace(&quot;[Measures].&quot;, &quot;&quot;).Replace(&quot;[&quot;, &quot;&quot;).Replace(&quot;]&quot;, &quot;&quot;) + &quot;&#8217;&quot;;<br />
                    else<br />
                        res += &quot; OR MEASURE_NAME =&#8217;&quot; + myMeasures[i].Replace(&quot;[Measures].&quot;, &quot;&quot;).Replace(&quot;[&quot;, &quot;&quot;).Replace(&quot;]&quot;, &quot;&quot;) + &quot;&#8217;&quot;;<br />
                }</p>
<p>                string query = &quot;select [CATALOG_NAME],[CUBE_NAME],MEASURE_NAME, DATA_TYPE,EXPRESSION,MEASURE_IS_VISIBLE,MEASUREGROUP_NAME,MEASURE_DISPLAY_FOLDER,DEFAULT_FORMAT_STRING  from $system.mdschema_measures where &quot; + res;<br />
                using (AdomdCommand cmd = new AdomdCommand(query, conn))<br />
                {<br />
                    DataTable tblMeasureType = new DataTable();<br />
                    AdomdDataAdapter da = new AdomdDataAdapter(cmd);<br />
                    da.Fill(tblMeasureType);<br />
                    return tblMeasureType;<br />
                }</p>
<p>            }<br />
            catch (Exception)<br />
            {<br />
                return null;<br />
            }<br />
        }</p>
<p>        #endregion<br />
[/csharp]</p>
<p>So in the table <em>tblMeasureType</em>, we will get the data. In the column <em>DEFAULT_FORMAT_STRING </em>, you can see the actual type of your measure. It will show as &#8216;Currency&#8217; if it is a currency type and &#8216;Percentage&#8217; if it is a percentage type and &#8216;#,##&#8217; for the numbers. The <em>DEFAULT_FORMAT_STRING </em> actually describes each measures which are all available in the cube. And <em>DEFAULT_FORMAT_STRING </em>rowset contains the following columns. </p>
<li>CATALOG_NAME</li>
<li>SCHEMA_NAME</li>
<li>CUBE_NAME</li>
<li>MEASURE_NAME</li>
<li>MEASURE_UNIQUE_NAME</li>
<li>MEASURE_CAPTION</li>
<li>MEASURE_GUID</li>
<li>MEASURE_AGGREGATOR</li>
<li>DATA_TYPE</li>
<li>NUMERIC_PRECISION</li>
<li>NUMERIC_SCALE</li>
<li>MEASURE_UNITS</li>
<li>DESCRIPTION</li>
<li>EXPRESSION</li>
<li>MEASURE_IS_VISIBLE</li>
<li>LEVELS_LIST</li>
<li>MEASURE_NAME_SQL_COLUMN_NAME</li>
<li>MEASURE_UNQUALIFIED_CAPTION</li>
<li>MEASUREGROUP_NAME</li>
<li>MEASURE_DISPLAY_FOLDER</li>
<li>DEFAULT_FORMAT_STRING</li>
<p>You can always check <a href="https://msdn.microsoft.com/en-us/library/ms126250.aspx" target="_blank">here </a>to see for more information about <em>MDSCHEMA_MEASURES Rowset</em>.</p>
<p>As you can see the function accepts one parameter called <em>myMeasureCollection</em>, this is the collection of our measures and we are formatting the same as follows. </p>
<p>[csharp]<br />
 for (int i = 0; i &lt; myMeasures.Count; i++)<br />
                {<br />
                    //Format the measure name<br />
                    if (i == 0)<br />
                        res += &quot;MEASURE_NAME =&#8217;&quot; + myMeasures[i].Replace(&quot;[Measures].&quot;, &quot;&quot;).Replace(&quot;[&quot;, &quot;&quot;).Replace(&quot;]&quot;, &quot;&quot;) + &quot;&#8217;&quot;;<br />
                    else<br />
                        res += &quot; OR MEASURE_NAME =&#8217;&quot; + myMeasures[i].Replace(&quot;[Measures].&quot;, &quot;&quot;).Replace(&quot;[&quot;, &quot;&quot;).Replace(&quot;]&quot;, &quot;&quot;) + &quot;&#8217;&quot;;<br />
                }<br />
[/csharp]</p>
<p>The <em>myMeasureCollection</em> is a string variable which has the values in the format of [Measures].[My Measure 1]||[Measures].[My Measure 2]||[Measures].[My Measure 3]. That is why we are splitting the values with || as follows.</p>
<p>[csharp]<br />
 myMeasures = myMeasureCollection.Split(new string[] { &quot;||&quot; }, StringSplitOptions.None).ToList();<br />
[/csharp]</p>
<p>I hope everything is clear. Have a happy coding. </p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Have you ever wanted to do this requirement? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/find-datatype-of-each-measures-in-ssas-mdx-queries/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
