Friday, December 31, 2010

.CurrentOrdinal (Iteration in MDX)

Today I was trying to understand one of the queries found in MSDN for currentordinal and was keen to share my understanding. It was good to see how iteration is happening here and how the current co-ordinate values can be checked against other values.


WITH SET [PrdTies] AS 
Filter
 (
       Order
       (
           NonEmpty
           (
              {
                      [Product].[Product Categories].[Product].&[471], --4079
                      [Product].[Product Categories].[Product].&[433], --787
                      [Product].[Product Categories].[Product].&[434], --648
                      [Product].[Product Categories].[Product].&[475]  --787
              } 
              ,[Measures].[Reseller Order Quantity]
       )
      ,[Measures].[Reseller Order Quantity]
      ,BDESC
 ) AS OrdPrds,
 --NOT --commented for now.
 (
       OrdPrds.CurrentOrdinal < OrdPrds.Count 
       AND 
       [Measures].[Reseller Order Quantity]= 
       ( [Measures].[Reseller Order Quantity],OrdPrds.Item(OrdPrds.CurrentOrdinal)) 
       --Compares whether currentmember measure value = measure value for any other member
       --The current member value is compared with value of members after the current coordinate
        --As the member value is compared with members after current coordinate, we do not need to consider  
          the last member
       --Now this gets only 433
 )
OR 
(
        OrdPrds.CurrentOrdinal > 1 
       AND [Measures].[Reseller Order Quantity] = 
       ([Measures].[Reseller Order Quantity], OrdPrds.Item(OrdPrds.CurrentOrdinal-2))
      --but the value of 475 is same as 433. It does not come in first part. but this also qualifies
      --so compare with previous member by doing -2 (-1 compares with self)
)
 )
 
SELECT {[Measures].[Reseller Order Quantity]} ON 0, [PrdTies] ON 1
FROM [Adventure Works]
Additionally you might want to look at this

ADOMD fetches Cube Details

Using ADOMD to fetch details of dimension, roles and Allowed Set in permission

System.Text.StringBuilder result = new System.Text.StringBuilder();
using (AdomdConnection conn = new AdomdConnection("Data Source=localhost;Initial Catalog=Adventure Works DW;Provider=MSOLAP.2;Integrated Security=SSPI;Persist Security Info=False;"))
{
    conn.Open();
    foreach (CubeDef cube in conn.Cubes)
    {
         if (cube.Name.StartsWith("$"))
           continue;

         if (cube.Name == "Adventure Works")
        {
             result.AppendLine(cube.Name);
            foreach (Microsoft.AnalysisServices.AdomdClient.Dimension dim in cube.Dimensions)
            {
                   result.Append("\t");
                   result.AppendLine(dim.Name);
            }
            foreach (Microsoft.AnalysisServices.AdomdClient.NamedSet set in cube.NamedSets)
            {
                   result.Append("\t");
                   result.AppendLine(set.Name);
            }
        }
     }
     conn.Close();
}

Server objServer = new Server();
string strConnection = "Data Source=localhost;Initial Catalog=Adventure Works DW;Provider=MSOLAP.2;Integrated Security=SSPI;Persist Security Info=False;";

if (objServer.Connected)
    objServer.Disconnect();

objServer.Connect(strConnection);
Database db = objServer.Databases["Adventure Works DW"];
for (int i=0;i<db.Roles.Count;i++)
{
    Role role = db.Roles[i];
    result.Append("\t");
    result.AppendLine(role.Name);
}

Cube cube1 = db.Cubes.FindByName("Adventure Works");
foreach (CubeDimensionPermission cubeper in cube1.CubePermissions)
{
        foreach (AttributePermission attrperm in cubeper.AttributePermissions)
        {
          result.Append("\t");
          result.AppendLine(attrperm.AllowedSet[0].ToString());
        }
       
}
MessageBox.Show(result.ToString());

LinkWithin

Related Posts with Thumbnails