SPDataStore.CreateKpi-Methode
Speichert ein Key Performance Indicator (KPI) Objekt als Inhaltstyp in einer SharePoint-Liste.
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
)
Parameter
listUrl
Typ: System.StringDie serverrelative URL der SharePoint-Liste um das Objekt zu speichern. Beispiel: /BI Center/Lists/PerformancePoint Content.
kpi
Typ: Microsoft.PerformancePoint.Scorecards.KpiDas KPI-Objekt speichern, einen Wert für die Eigenschaft erforderlich Name gibt.
Rückgabewert
Typ: Microsoft.PerformancePoint.Scorecards.Kpi
Das neue Objekt, das enthält aktualisierte Informationen so ihre Nummer und Version.
Implementiert
IBIMonitoringStore.CreateKpi(String, Kpi)
Beispiele
Die folgenden Codebeispiele zeigen, wie auf eine private Methode verwenden, um einen KPI erstellen und Aufrufen von CreateKpi(String, Kpi) , um sie im Repository zu speichern. Im ersten Beispiel wird ein KPI mit festen-Istwerten und Zielwerten und im zweite Beispiel erstellt einen KPI, der eine OLAP-Datenquelle verwendet.
Bevor Sie diese Codebeispiele kompilieren können, müssen Sie Folgendes tun:
Konfigurieren Sie die Entwicklungsumgebung, und erstellen Sie ein C#-Klassenbibliotheksprojekt in Visual Studio. Informationen zum Konfigurieren einer Entwicklungsumgebung finden Sie unter Einrichten einer allgemeinen Entwicklungsumgebung für SharePoint 2013.
Die Microsoft.PerformancePoint.Scorecards.Client, Microsoft.PerformancePoint.Scorecards.ServerCommon und Microsoft.PerformancePoint.Scorecards.Store DLLs als Verweise auf Ihr Projekt hinzufügen. Weitere Informationen zu PerformancePoint-Dienste DLLs finden Sie unter PerformancePoint Services DLLs Used in Development Scenarios.
Fügen Sie die folgenden using Direktiven zu Ihrer Klasse.
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);
}