Sibeesh Passion

Top Menu

  • Home
  • Search
  • About
  • Privacy Policy

Main Menu

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Home
  • Search
  • About
  • Privacy Policy

logo

Sibeesh Passion

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment

  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins

  • Post Messages to Microsoft Teams Using Python

  • Get Azure Blob Storage Blob Metadata Using PowerShell

  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines

MDX QuerySSAS
Home›Microsoft ADOMD›MDX Query›Find Datatype Of Each Measures In SSAS MDX Queries

Find Datatype Of Each Measures In SSAS MDX Queries

By SibeeshVenu
February 22, 2016
1403
0
Share:

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 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.

Background

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 here in stack overflow.

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’t have only string and numbers as the types in the cube, this post will definitely help you.

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 here: ASSP – Analysis Services Stored Procedure Project.

Using the code

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.

[sql]
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
[/sql]

Now before going further, please make sure that you have included AnalysisServices Adomd Client.

[csharp]
using Microsoft.AnalysisServices.AdomdClient;
[/csharp]

Now we will create the function which will give you the data about the datatypes of your measures.

[csharp]
#region Return the data types of measures
/// <summary>
/// FindMeasureDataTypes-Find the measure type whetehr it is a currency or a percentage or a number
/// </summary>
/// <param name="serverName"></param>
/// <param name="databaseName"></param>
/// <param name="myMeasureCollection"></param>
public DataTable FindMeasureDataTypes(string serverName, string databaseName, string myMeasureCollection)
{

try
{
string res = string.Empty;
List<string> myMeasures = new List<string>();

//Buiding the connection string start
StringBuilder sbConnectionString = new StringBuilder();
sbConnectionString.Append("Provider=MSOLAP;data source=");
sbConnectionString.Append(serverName + ";initial catalog=" + databaseName + ";Integrated Security=SSPI;Persist Security Info=False;");
//Buiding the connection string start

AdomdConnection conn = new AdomdConnection(sbConnectionString.ToString());
myMeasures = myMeasureCollection.Split(new string[] { "||" }, StringSplitOptions.None).ToList();

for (int i = 0; i < myMeasures.Count; i++)
{
//Format the measure name
if (i == 0)
res += "MEASURE_NAME =’" + myMeasures[i].Replace("[Measures].", "").Replace("[", "").Replace("]", "") + "’";
else
res += " OR MEASURE_NAME =’" + myMeasures[i].Replace("[Measures].", "").Replace("[", "").Replace("]", "") + "’";
}

string query = "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 " + res;
using (AdomdCommand cmd = new AdomdCommand(query, conn))
{
DataTable tblMeasureType = new DataTable();
AdomdDataAdapter da = new AdomdDataAdapter(cmd);
da.Fill(tblMeasureType);
return tblMeasureType;
}

}
catch (Exception)
{
return null;
}
}

#endregion
[/csharp]

So in the table tblMeasureType, we will get the data. In the column DEFAULT_FORMAT_STRING , you can see the actual type of your measure. It will show as ‘Currency’ if it is a currency type and ‘Percentage’ if it is a percentage type and ‘#,##’ for the numbers. The DEFAULT_FORMAT_STRING actually describes each measures which are all available in the cube. And DEFAULT_FORMAT_STRING rowset contains the following columns.

  • CATALOG_NAME
  • SCHEMA_NAME
  • CUBE_NAME
  • MEASURE_NAME
  • MEASURE_UNIQUE_NAME
  • MEASURE_CAPTION
  • MEASURE_GUID
  • MEASURE_AGGREGATOR
  • DATA_TYPE
  • NUMERIC_PRECISION
  • NUMERIC_SCALE
  • MEASURE_UNITS
  • DESCRIPTION
  • EXPRESSION
  • MEASURE_IS_VISIBLE
  • LEVELS_LIST
  • MEASURE_NAME_SQL_COLUMN_NAME
  • MEASURE_UNQUALIFIED_CAPTION
  • MEASUREGROUP_NAME
  • MEASURE_DISPLAY_FOLDER
  • DEFAULT_FORMAT_STRING
  • You can always check here to see for more information about MDSCHEMA_MEASURES Rowset.

    As you can see the function accepts one parameter called myMeasureCollection, this is the collection of our measures and we are formatting the same as follows.

    [csharp]
    for (int i = 0; i < myMeasures.Count; i++)
    {
    //Format the measure name
    if (i == 0)
    res += "MEASURE_NAME =’" + myMeasures[i].Replace("[Measures].", "").Replace("[", "").Replace("]", "") + "’";
    else
    res += " OR MEASURE_NAME =’" + myMeasures[i].Replace("[Measures].", "").Replace("[", "").Replace("]", "") + "’";
    }
    [/csharp]

    The myMeasureCollection 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.

    [csharp]
    myMeasures = myMeasureCollection.Split(new string[] { "||" }, StringSplitOptions.None).ToList();
    [/csharp]

    I hope everything is clear. Have a happy coding.

    Conclusion

    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.

    Your turn. What do you think?

    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.

    Kindest Regards
    Sibeesh Venu

    TagsDatatype Of Each MeasuresDMV QueryMDXMDX QuerySSAS
    Previous Article

    Generate Database Scripts With Data In SQL ...

    Next Article

    Change Page Layout Dynamically Using jQuery Layout ...

    0
    Shares
    • 0
    • +
    • 0
    • 0
    • 0

    SibeeshVenu

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer.

    Related articles More from author

    • MDX Query

      Filters in MDX Queries

      July 6, 2015
      By SibeeshVenu
    • Convert data reader to data table
      Microsoft ADOMDSSAS

      Convert Data Reader To Datatable

      November 17, 2015
      By SibeeshVenu
    • Excel Export In MDX
      .NETASP.NETMDX QuerySQL

      Export MDX Result As Excel

      October 28, 2015
      By SibeeshVenu
    0

    My book

    Asp Net Core and Azure with Raspberry Pi Sibeesh Venu

    YouTube

    MICROSOFT MVP (2016-2022)

    profile for Sibeesh Venu - Microsoft MVP

    Recent Posts

    • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment
    • Build, Deploy, Configure CI &CD Your Static Website in 5 mins
    • Easily move data from one COSMOS DB to another
    • .NET 8 New and Efficient Way to Check IP is in Given IP Range
    • Async Client IP safelist for Dot NET
    • Post Messages to Microsoft Teams Using Python
    • Get Azure Blob Storage Blob Metadata Using PowerShell
    • Deploy .net 6 App to Azure from Azure DevOps using Pipelines
    • Integrate Azure App Insights in 1 Minute to .Net6 Application
    • Azure DevOps Service Connection with Multiple Azure Resource Group

    Tags

    Achievements (35) Angular (14) Angular 5 (7) Angular JS (15) article (10) Article Of The Day (13) Asp.Net (14) Azure (65) Azure DevOps (10) Azure Function (10) Azure IoT (7) C# (17) c-sharp corner (13) Career Advice (11) chart (11) CSharp (7) CSS (7) CSS3 (6) HighChart (10) How To (9) HTML5 (10) HTML5 Chart (11) Interview (6) IoT (11) Javascript (10) JQuery (82) jquery functions (9) JQWidgets (15) JQX Grid (17) Json (7) Microsoft (8) MVC (20) MVP (9) MXChip (7) News (18) Office 365 (7) Products (10) SQL (20) SQL Server (15) Visual Studio (10) Visual Studio 2017 (7) VS2017 (7) Web API (12) Windows 10 (7) Wordpress (9)
    • .NET
    • Achievements
    • ADO.NET
    • Android
    • Angular
    • Arduino
    • Article Of The Day
    • ASP.NET
    • Asp.Net Core
    • Automobile
    • Awards
    • Azure
    • Azure CDN
    • azure devops
    • Blockchain
    • Blog
    • Browser
    • C-Sharp Corner
    • C#
    • Career Advice
    • Code Snippets
    • CodeProject
    • Cognitive Services
    • Cosmos DB
    • CSS
    • CSS3
    • Data Factory
    • Database
    • Docker
    • Drawings
    • Drill Down Chart
    • English
    • Excel Programming
    • Exporting
    • Facebook
    • Fun
    • Gadgets
    • GitHub
    • GoPro
    • High Map
    • HighChart
    • How to
    • HTML
    • HTML5
    • Ignite UI
    • IIS
    • Interview
    • IoT
    • JavaScript
    • JQuery
    • jQuery UI
    • JQWidgets
    • JQX Grid
    • Json
    • Knockout JS
    • Linux
    • Machine Learning
    • Malayalam
    • Malayalam Poems
    • MDX Query
    • Microsoft
    • Microsoft ADOMD
    • Microsoft MVP
    • Microsoft Office
    • Microsoft Technologies
    • Microsoft Windows
    • Microsoft Windows Server
    • Mobile
    • MongoDB
    • Monthly Winners
    • MVC
    • MVC Grid
    • MySQL
    • News
    • Node JS
    • npm
    • Number Conversions
    • October 2015
    • Office 365
    • Office Development
    • One Plus
    • Outlook
    • Page
    • PHP
    • Poems
    • PowerShell
    • Products
    • Q&A
    • Raspberry PI
    • React
    • SEO
    • SharePoint
    • Skype
    • Social Media
    • Software
    • Spire.Doc
    • Spire.PDF
    • Spire.XLS
    • SQL
    • SQL Server
    • SSAS
    • SSMS
    • Storage In HTML5
    • Stories
    • Third Party Software Apps
    • Tips
    • Tools
    • Translator Text
    • Uncategorized
    • Unit Testing
    • UWP
    • VB.Net
    • Videos
    • Virtual Machine
    • Visual Studio
    • Visual Studio 2017
    • Wamp Server
    • Web API
    • Web Platform Installer
    • Webinars
    • WebMatrix
    • Windows 10
    • Windows 7
    • Windows 8.1
    • Wordpress
    • Writing

    ABOUT ME

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer. If you would like to know more about me, you can read my story here.

    Contact Me

    • info@sibeeshpassion.com

    Pages

    • About
    • Search
    • Privacy Policy
    • About
    • Search
    • Privacy Policy
    © Copyright Sibeesh Passion 2014-2025. All Rights Reserved.
    Go to mobile version