Share via


SPDataStore.CreateKpi method

Saves a key performance indicator (KPI) object as a content type in a SharePoint list.

Namespace:  Microsoft.PerformancePoint.Scorecards.Store
Assembly:  Microsoft.PerformancePoint.Scorecards.Store (in Microsoft.PerformancePoint.Scorecards.Store.dll)

Syntax

'Declaration
Public Function CreateKpi ( _
    listUrl As String, _
    kpi As Kpi _
) As Kpi
'Usage
Dim instance As SPDataStore
Dim listUrl As String
Dim kpi As Kpi
Dim returnValue As Kpi

returnValue = instance.CreateKpi(listUrl, _
    kpi)
public Kpi CreateKpi(
    string listUrl,
    Kpi kpi
)

Parameters

  • listUrl
    Type: System.String

    The server-relative URL of the SharePoint list to save the object to. Example: /BI Center/Lists/PerformancePoint Content.

Return value

Type: Microsoft.PerformancePoint.Scorecards.Kpi
The new object, which contains updated information such its location and version number.

Implements

IBIMonitoringStore.CreateKpi(String, Kpi)

Examples

The following code examples show how to use a private method to create a KPI and to call CreateKpi(String, Kpi) to save it to the repository. The first example creates a KPI with fixed actual and target values, and the second example creates a KPI that uses an OLAP data source.

Before you can compile these code examples, you must do the following:

  • Configure your development environment and create a C# class library project in Visual Studio. For information about configuring a development environment, see Set up a general development environment for SharePoint 2013.

  • Add the Microsoft.PerformancePoint.Scorecards.Client, Microsoft.PerformancePoint.Scorecards.ServerCommon, and Microsoft.PerformancePoint.Scorecards.Store DLLs as references to your project. For more information about PerformancePoint Services DLLs, see PerformancePoint Services DLLs Used in Development Scenarios.

  • Add the following using directives to your class.

    using Microsoft.PerformancePoint.Scorecards;
    using Microsoft.PerformancePoint.Scorecards.Indicators;
    using Microsoft.PerformancePoint.Scorecards.Store;
    
// Create a KPI that uses fixed values for the actual and target values, based on the following parameters:
//   - kpiName is the name for the KPI.
//   - listUrl is the server-relative URL of the list to save the KPI to.
//         Example: "/BI Center/Lists/PerformancePoint Content"
// This method returns the new KPI.
private Kpi CreateFixedValueKPI(string kpiName, string listUrl)
{
    if (String.IsNullOrEmpty(kpiName))
        throw new ArgumentException("The name must not be null or empty.");
    if (String.IsNullOrEmpty(listUrl))
        throw new ArgumentException("The list URL must not be null or empty.");

    Kpi newKpi = Kpi.CreateNew();
    newKpi.Name.Text = kpiName;
    newKpi.Description.Text = "Created with the SDK.";

    // Create a fixed value actual and set the value to 80.
    newKpi.Actual.DataSourceLocation = new RepositoryLocation(Constants.FixedValuesDataSourceLocationKey);
    newKpi.Actual.ModelCurrent = 80; 

    // Create a fixed value target and set the value to 100.
    Target target1 = new Target();
    target1.Guid = Guid.NewGuid();
    target1.Name.Text = "Target";
    target1.DataSourceLocation = newKpi.Actual.DataSourceLocation;
    target1.ModelCurrent = 100;
    target1.IndicatorLocation =
        BuiltinIndicators.GetIndicatorByCode(BuiltinIndicators.IndicatorCode.ShapesJagged3Small).Location;
    target1.Pattern = KpiPattern.IncreasingIsBetter;
    target1.RelatedActualId = newKpi.Actual.Guid;

    // Set up the banding for three bands:  < .5; .5 - 1.0; > 1.0.
    target1.Banding.ActualWorst = 0;
    target1.Banding.Type = BandType.Normalized;
    target1.Banding.SpreadMaximum = 1.2M;
    target1.Banding.SpreadMinimum = 0;
    target1.Banding.CustomBoundary.Add(.50M);
    target1.Banding.CustomBoundary.Add(1M);
    newKpi.Targets.Add(target1);

    // Call the CreateKpi method to save the new KPI to the specified list.
    // TODO: Handle exceptions from this call.
    return SPDataStore.GlobalDataStore.CreateKpi(listUrl, newKpi);
}
// Create a KPI that uses an Analysis Services data source, based on the following parameters:
//   - kpiName is the name for the KPI.
//   - listUrl is the server-relative URL of the list to save the KPI to. Example: 
//         "/BI Center/Lists/PerformancePoint Content"
//   - dataSource is the data source to use for the actual and target values.
// This method returns the new KPI.
private Kpi CreateKpiWithDatasource(string kpiName, string listUrl, DataSource dataSource)
{
    if (String.IsNullOrEmpty(kpiName))
        throw new ArgumentException("The name must not be null or empty.");
    if (String.IsNullOrEmpty(listUrl))
        throw new ArgumentException("The list URL must not be null or empty.");
    if (null == dataSource)
        throw new ArgumentNullException("dataSource");

    Kpi newKpi = Kpi.CreateNew();
    newKpi.Name.Text = kpiName;
    newKpi.Description.Text = "Analysis Services KPI created with the SDK.";
    newKpi.Actual.DataSourceLocation = dataSource.Location;

    // Set the "actual" measure.
    DefaultDimensionSetting actualMeasureSettings = new DefaultDimensionSetting
                                                  {
                                                      DisplayName = "Measures",
                                                      UniqueName = "[Measures]",
                                                      IsMeasureDimension = true
                                                  };
    Member actualMeasure = new Member("[Measures].[Internet Gross Profit]")
                         {
                             Caption = "Internet Gross Profit",
                             DimensionName = "Measures.Measures",
                             DimensionUniqueName = "[Measures]",
                             MemberType = MemberType.Formula
                         };
    actualMeasureSettings.Members.Add(actualMeasure);
    newKpi.Actual.DefaultDimensionSettings.Add(actualMeasureSettings);

    // Add a dimension filter for the actual and set it to the year 2004.
    DefaultDimensionSetting actualFilterYear = new DefaultDimensionSetting
    {
        DisplayName = "Date.Date.Calendar",
        UniqueName = "[Date].[Calendar]",
        IsMeasureDimension = false
    };
    Member year2004 = new Member("[Date].[Calendar].[Calendar Year].&[2004]")
    {
        Caption = "CY 2004",
        LevelName = "[Date].[Calendar].[Calendar Year]",
        DimensionName = "Date.Date.Calendar",
        LevelDepth = 1,
        IsAllLevel = false,
        DimensionUniqueName = "[Date].[Calendar]",
        MemberType = MemberType.Regular
    };
    actualFilterYear.Members.Add(year2004);
    newKpi.Actual.DefaultDimensionSettings.Add(actualFilterYear);

    // Create the target.
    Target target1 = new Target();
    target1.Guid = Guid.NewGuid();
    target1.Name.Text = "Target";
    target1.IndicatorLocation =
        BuiltinIndicators.GetIndicatorByCode(BuiltinIndicators.IndicatorCode.SmileyA3Small).Location;
    target1.Pattern = KpiPattern.IncreasingIsBetter;
    target1.RelatedActualId = newKpi.Actual.Guid;

    // Set up the banding for three bands:  < .5; .5 - 1.0; > 1.0
    target1.Banding.ActualWorst = 0;
    target1.Banding.Type = BandType.Normalized;
    target1.Banding.SpreadMaximum = 1.2M;
    target1.Banding.SpreadMinimum = 0;
    target1.Banding.CustomBoundary.Add(.50M);
    target1.Banding.CustomBoundary.Add(1M);
    target1.DataSourceLocation = dataSource.Location;

    // Set the target. Use a custom formula to set the target at 10% growth from 2003.
    target1.IsCustomCurrentFormula = true;
    target1.CurrentFormula =
        "([Measures].[Internet Gross Profit], [Date].[Calendar].[Calendar Year].&[2003]) * 1.1";
    newKpi.Targets.Add(target1);

    // Call the CreateKpi method to save the new KPI to the specified list.
    // TODO: Handle exceptions from this call.
    return SPDataStore.GlobalDataStore.CreateKpi(listUrl, newKpi);
}

See also

Reference

SPDataStore class

SPDataStore members

Microsoft.PerformancePoint.Scorecards.Store namespace