Search code examples
c#ssasmdxadomd.net

SSAS / MDX / ADOMD.NET - Retrieve last updated date from a cube


I'm trying to retrieve the last updated date from a cube. I have a process that runs twice a day (eventually I would like it to be able to be executed at a click of a button but thats further down the line). I'm quite new to all of this.

So for now I'd just like to retrieve a datetime value through an MDX query of when that process was last run.

Here is my connection string:

public AdomdConnection conn = new AdomdConnection("Data Source=BTN-SQL1;Initial Catalog=BTNTurboAnalysisServices;");

The process is called: Process SSAS

Then I've got this far, but I dont know what to write in my MDX query:

conn.Open();

    AdomdCommand cmd = conn.CreateCommand();

    cmd.CommandText = @"
                      SELECT  
                      NON EMPTY   { [] } ON COLUMNS,
                                  { [] } ON ROWS
                      FROM        [Sales Analysis]
                      ";

Any help would be appreciated, thanks!


Solution

  • You could use the schema to get that information.

    I'm using ADODB objects, but you can find the corresponding ADOMD objects.

    Set objRst = objConnection.OpenSchema(32, Array(strCatalog, vbNullString, strCube))
    dtLast = objRs("LAST_DATA_UPDATE")
    

    Sorry... wrong answer...

    Try with the LASTSIBLING function: Select {[Measures].[Internet Sales Amount]} On Columns, {[Date].[Fiscal].[Fiscal Year].&[2002].LASTSIBLING} On Rows From [Adventure Works]