简体   繁体   中英

Retrieve Cellset Value in SSAS\MDX

Im writing SSAS MDX queries involving more than 2 axis' to retrieve a value. Using ADOMD.NET, I can get the returned cellset and determine the value by using

lblTotalGrossSales.Text = CellSet.Cells(0).Value

Is there a way I can get the CellSet's Cell(0) Value in my MDX query, instead of relying on the data returning to ADOMD.NET?

thanks!


Edit 1: - Based on Daryl's comment, here's some elaboration on what Im doing. My current query is using several axis', which is:

SELECT {[Term Date].[Date Calcs].[MTD]} ON 0, 
{[Sale Date].[YQMD].[DAY].&[20121115]} ON 1, 
{[Customer].[ID].[All].[A612Q4-35]} ON 2, 
{[Measures].[Loss]} ON 3 
FROM OUR_CUBE

If I run that query in Management Studio, I am told Results cannot be displayed for cellsets with more than two axes - which makes sense since.. you know.. there's more than 2 axes. However, if I use ADOMD.NET to run this query in-line, and read the returning value into an ADOMD.NET cellset, I can check the value at cell "0", giving me my value... which as I understand it (im a total noob at cubes) is the value sitting where all these values intersect.

So to answer your question Daryl, what I'd love to have is the ability to have the value here returned to me, not have to read in a cell set into the calling application. Why you may ask? Well.. ultimately I'd love to have one query that performs several multi-axis queries to return the values. Again.. Im VERY new to cubes and MDX, so it's possible Im going at this all wrong (Im a .NET developer by trade).

Simplify your query to return two axis;

SELECT {[Measures].[Loss]} ON 0, {[Term Date].[Date Calcs].[MTD] * [Sale Date].[YQMD].[DAY].&[20121115] * [Customer].[ID].[All].[A612Q4-35]} ON 1 FROM OUR_CUBE

and then try the following to access the cellset;

 string connectionString =  "Data Source=localhost;Catalog=AdventureWorksDW2012";
        //Create a new string builder to store the results
        System.Text.StringBuilder result = new System.Text.StringBuilder();
        AdomdConnection conn = new AdomdConnection(connectionString);
        //Connect to the local serverusing (AdomdConnection conn = new AdomdConnection("Data Source=localhost;"))
        {
            conn.Open();

            //Create a command, using this connection
            AdomdCommand cmd = conn.CreateCommand();
            cmd.CommandText = @"SELECT {  [Measures].[Unit Price]  } ON COLUMNS , {[Product].[Color].[Color].MEMBERS-[Product].[Color].[]} * [Product].[Model Name].[Model Name]ON ROWS FROM [Adventure Works] ;";

            //Execute the query, returning a cellset
            CellSet cs = cmd.ExecuteCellSet();

            //Output the column captions from the first axis//Note that this procedure assumes a single member exists per column.
            result.Append("\t\t\t");

            TupleCollection tuplesOnColumns = cs.Axes[0].Set.Tuples;

            foreach (Microsoft.AnalysisServices.AdomdClient.Tuple column in tuplesOnColumns)
            {
                result.Append(column.Members[0].Caption + "\t");

            }
            result.AppendLine();

            //Output the row captions from the second axis and cell data//Note that this procedure assumes a two-dimensional cellset
            TupleCollection tuplesOnRows = cs.Axes[1].Set.Tuples;
            for (int row = 0; row < tuplesOnRows.Count; row++)
            {
                for (int members = 0; members < tuplesOnRows[row].Members.Count; members++ )
                {
                    result.Append(tuplesOnRows[row].Members[members].Caption + "\t");
                }


                for (int col = 0; col < tuplesOnColumns.Count; col++)
                {
                    result.Append(cs.Cells[col, row].FormattedValue + "\t");
                }
                result.AppendLine();
            }
            conn.Close();

            TextBox1.Text = result.ToString();
        } // using connection

Source : Retrieving Data Using the CellSet

This is fine upto select on columns and on Rows. It will be helpful analyze how to traverse sub select queries from main query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM