Mittwoch, 28. Oktober 2015

Custom Drillthrough on YTD Calculation

As everybody knows, a Drillthrough on Calculations is not possible. In my actual project we make some YtD Calculations. Now the business wanted in the Drillthrough to get all effected rows for that.
The solution is to build your own custom drillthrough based on the ASSP by making an own Drillthrough for each Period and then merging the resultset.

Step1: I'm using the built-in function of ASSP to capture my currentCellAtributes.

Step2: checking on which Level in my Datedimension the user is analysing. This is be done by checking which is the lowest level of the hierarchy with a selected member except the All-Member.
In the follwoing example the user is analysing on Month:

/*Declaring some variables*/
string monthuniquekey = "";
string monthkey = "";
List<string> months = new List<string>();

/*Getting UniqueKey of the Month member*/
monthuniquekey = currentCellAttribute.Substring(currentCellAttribute.IndexOf("[Period].[Month]"), 26);

/*Getting Key of the Month member*/
monthkey = monthuniquekey.Substring(monthuniquekey.IndexOf("&[") + 2, 6);

/*Getting the Year Key of the selected Month member*/
string year = monthkey.Substring(0, 4);

/*Building up a list with all months which are needed for Drillthrough*/
for (int i = 1; i <= Int32.Parse(monthkey.Substring(4, 2)); i++)
{
  months.Add(year + i.ToString().PadLeft(2, '0'));
}

/*Iterate over all months in my list*/
foreach (string month in months)
{
  string tempCellAttributes = currentCellAttribute;

/*Need to modify the CellAttributes for the Drillthrough command to replace the selected month by the actual from the iteration*/
  tempCellAttributes = tempCellAttributes.Replace(monthuniquekey, "[Period].[Month].&["+  month + "]");

/*Need to modify the CellAttributes for the Drillthrough command to replace the Cumulative type from YtD to Not Cumulated*/
  tempCellAttributes = tempCellAttributes.Replace("[Cumulation Type].[Cumulation Type].&[2]", "[Cumulation Type].[Cumulation Type].&[1]");

/*Fill a Temp Datatable with the result from the Drillthrough*/
  DataTable dttemp = General.ExecuteAccountDrillthrough("drillthrough select (" + tempCellAttributes + ") on 0 from [Cube] return " + sReturnColumns);

/*Finally merge the Temp Datatable with the Main Datatable*/
  dt.Merge(dttemp);
}


 
Step3: Actually there is some "Bug" with the built in function "ExecuteDrillthrough". I always got errors when it comes to filling the Datatable with the measures value. Therefor I created a new Datatable and specify the datatypes of each column seperatly. Specially for the measures I need decimal datatype:

DataTable dtResult = new DataTable();
dtResult.Columns.Add("Ultimo Volume on Balance - liability side", typeof(decimal));


Keine Kommentare:

Kommentar veröffentlichen