<?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>SSAS &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/category/database/sql/ssas/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 10 Jul 2018 11:42:40 +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>SSAS &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Find Datatype Of Each Measures In SSAS MDX Queries</title>
		<link>https://www.sibeeshpassion.com/find-datatype-of-each-measures-in-ssas-mdx-queries/</link>
					<comments>https://www.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://www.sibeeshpassion.com/find-datatype-of-each-measures-in-ssas-mdx-queries/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Convert Data Reader To Datatable</title>
		<link>https://www.sibeeshpassion.com/convert-data-reader-to-datatable/</link>
					<comments>https://www.sibeeshpassion.com/convert-data-reader-to-datatable/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 17 Nov 2015 09:45:56 +0000</pubDate>
				<category><![CDATA[Microsoft ADOMD]]></category>
		<category><![CDATA[SSAS]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Data reader]]></category>
		<category><![CDATA[Data reader to Data table]]></category>
		<category><![CDATA[Generate table schema]]></category>
		<category><![CDATA[GetSchemaTable]]></category>
		<category><![CDATA[LoadDataRow]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10968</guid>

					<description><![CDATA[In this article we will learn how we can convert Microsoft ADOMD data reader to datatable. As you all know a data reader is the most efficient way for looping through the data. Performance wise a data reader is faster than any of the other way like data adapter and cell set in MDX result. So in few situations you may need to convert this data reader to a data table. Here in this post we will discuss how we can convert it. I hope you will like it. Background For the past few months I have been working with [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we will learn how we can convert Microsoft ADOMD data reader to datatable. As you all know a data reader is the most efficient way for looping through the data. Performance wise a data reader is faster than any of the other way like data adapter and cell set in MDX result. So in few situations you may need to convert this data reader to a data table. Here in this post we will discuss how we can convert it. I hope you will like it.</p>
<p><strong>Background</strong></p>
<p>For the past few months I have been working with Microsoft ADOMD data sources. And I have written some article also that will describe the problems I have encountered so far. If you are new to ADOMD I strongly recommend that read my previous articles that you may find useful when you work with ADOMD data sources. You can find those article links here: <a href="http://sibeeshpassion.com/category/microsoft-adomd/" target="_blank">ADOMD Data Sources </a></p>
<p><strong>Why </strong></p>
<p>You might think, why I am not using other two ways (data adapter and cell set). I will answer it here. I am handling large set of data, so when I use data adapter and cell set it was bit slow to get the output. So I was just checking the performance by using data reader. It was fast enough when I use data reader. So we can order these three as following by performance.</p>
<blockquote><p>Data reader >> Data Adapter >> Cell Set</p></blockquote>
<p><strong>Using the code</strong></p>
<p>The following is the function that does what was explained above.</p>
<p>[csharp]<br />
 #region Convert Datareader toDatatable<br />
        /// &lt;summary&gt;<br />
        /// Convert Datareader toDatatable<br />
        /// &lt;/summary&gt;<br />
        /// &lt;param name=&quot;query&quot;&gt;&lt;/param&gt;<br />
        /// &lt;param name=&quot;myConnection&quot;&gt;&lt;/param&gt;<br />
        public DataTable ConvertDataReaderToDataTable(string query, string myConnection)<br />
        {<br />
            AdomdConnection conn = new AdomdConnection(myConnection);<br />
            try<br />
            {<br />
                try<br />
                {<br />
                    conn.Open();<br />
                }<br />
                catch (Exception)<br />
                {<br />
                }<br />
                using (AdomdCommand cmd = new AdomdCommand(query, conn))<br />
                {<br />
                    AdomdDataReader rdr;<br />
                    cmd.CommandTimeout = connectionTimeout;<br />
                    using (AdomdDataAdapter ad = new AdomdDataAdapter(cmd))<br />
                    {<br />
                        DataTable dtData = new DataTable(&quot;Data&quot;);<br />
                        DataTable dtSchema = new DataTable(&quot;Schema&quot;);<br />
                        rdr = cmd.ExecuteReader();<br />
                        if (rdr != null)<br />
                        {<br />
                            dtSchema = rdr.GetSchemaTable();<br />
                            foreach (DataRow schemarow in dtSchema.Rows)<br />
                            {<br />
                                dtData.Columns.Add(schemarow.ItemArray[0].ToString(), System.Type.GetType(schemarow.ItemArray[5].ToString()));<br />
                            }<br />
                            while (rdr.Read())<br />
                            {<br />
                                object[] ColArray = new object[rdr.FieldCount];<br />
                                for (int i = 0; i &lt; rdr.FieldCount; i++)<br />
                                {<br />
                                    if (rdr[i] != null) ColArray[i] = rdr[i];<br />
                                }<br />
                                dtData.LoadDataRow(ColArray, true);<br />
                            }<br />
                            rdr.Close();<br />
                        }<br />
                        return dtData;<br />
                    }<br />
                }<br />
            }</p>
<p>            catch (Exception)<br />
            {<br />
                throw;<br />
            }<br />
            finally<br />
            {<br />
                conn.Close(false);<br />
            }<br />
        }<br />
        #endregion;<br />
[/csharp]</p>
<p>Here we are creating two data table dtData and dtSchema where dtData is for binding the data and dtSchema is for binding the schema.</p>
<p><em>Creating data tables</em></p>
<p>[csharp]<br />
 DataTable dtData = new DataTable(&quot;Data&quot;);<br />
                        DataTable dtSchema = new DataTable(&quot;Schema&quot;);<br />
[/csharp]</p>
<p><em>Execute data reader</em></p>
<p>Now we will execute the reader as follows.</p>
<p>[csharp]<br />
rdr = cmd.ExecuteReader();<br />
[/csharp]</p>
<p><em>Get the schema</em></p>
<p>To generate the schema, we can call the function GetSchemaTable() which is a part of your data reader.</p>
<blockquote><p>To use this function, you must include Microsoft.AnalysisServices.AdomdClient.dll</p></blockquote>
<p><em>Adding the columns headers to the dtData</em></p>
<p>The next thing is to add the header names to the data table dtData.</p>
<p>[csharp]<br />
foreach (DataRow schemarow in dtSchema.Rows)<br />
                            {<br />
                                dtData.Columns.Add(schemarow.ItemArray[0].ToString(), System.Type.GetType(schemarow.ItemArray[5].ToString()));<br />
                            }<br />
[/csharp]</p>
<p><em>Load the data to dtData </em></p>
<p>To load the data, we are using a function LoadDataRow() which expects an object as parameter. This will find and updates a specific row, if the matching row is not found, it will create an another row with the given values. </p>
<div id="attachment_10969" style="width: 608px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/11/Convert_data_reader_to_data_table.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-10969" src="http://sibeeshpassion.com/wp-content/uploads/2015/11/Convert_data_reader_to_data_table.png" alt="Convert data reader to data table" width="598" height="150" class="size-full wp-image-10969" srcset="/wp-content/uploads/2015/11/Convert_data_reader_to_data_table.png 598w, /wp-content/uploads/2015/11/Convert_data_reader_to_data_table-300x75.png 300w, /wp-content/uploads/2015/11/Convert_data_reader_to_data_table-400x100.png 400w" sizes="(max-width: 598px) 100vw, 598px" /></a><p id="caption-attachment-10969" class="wp-caption-text">Convert data reader to data table</p></div>
<p>[csharp]<br />
object[] ColArray = new object[rdr.FieldCount];<br />
                                for (int i = 0; i &lt; rdr.FieldCount; i++)<br />
                                {<br />
                                    if (rdr[i] != null) ColArray[i] = rdr[i];<br />
                                }<br />
                                dtData.LoadDataRow(ColArray, true);<br />
[/csharp]</p>
<p><strong>Conclusion</strong></p>
<p>Have you ever gone through this kind of requirement. Did I miss anything that you may think which is needed?. 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-Sharp Corner, Stack Overflow, Asp.Net Forums or Code Project instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I am able to.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/convert-data-reader-to-datatable/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
