Create KPIs Programmatically in PerformancePoint 2007

I created this web project while I was investigating the performancepoint API, it was really a very hard and silly task so I decided to share this code with you 🙂

Firstly, Add a reference to :
\Microsoft Office PerformancePoint Server\3.0\Monitoring\Assemblies\Microsoft.PerformancePoint.Scorecards.Common.dll

using Microsoft.PerformancePoint.Scorecards;
using System.Net;

public partial class _Default : System.Web.UI.Page
{
private Kpi kpi_wows;
private PmService Publisher;

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Publisher = (PmService)PmService.CreateInstance(“http://localhost:40000/webservice/pmservice.asmx”);
Publisher.Credentials = CredentialCache.DefaultNetworkCredentials;

}
protected void Page_Load(object sender, EventArgs e)
{
CreateKPIandSetSomeProperties();
}

private void CreateKPIandSetSomeProperties()
{
// Create a new kpi instance
kpi_wows = Kpi.CreateNew();
// Setting its name
kpi_wows.Name.Text = “zzz”;
// Setting the Owner
BpmPropertyUser Owner = new BpmPropertyUser();
Owner.Login = @”Server\Administrator”;
kpi_wows.Owner = Owner;
// setting the actual
KpiMeasure ActualMeasure = new KpiMeasure();
ActualMeasure.Guid = Guid.NewGuid();
ActualMeasure.ModelCurrent = 345M;
BpmPropertyText ActualName = new BpmPropertyText();
ActualName.Text = “The Actual”;
ActualMeasure.Name = ActualName;
ActualMeasure.ValueSource = ValueSources.MaxRollup;
kpi_wows.Actual = ActualMeasure;
// Setting the Target
Target ATarget = new Target();
ATarget.Guid = Guid.NewGuid();
ATarget.ModelCurrent = 656M;
BpmPropertyText TargetName = new BpmPropertyText();
TargetName.Text = “The Target”;
ATarget.Name = TargetName;
// Scoring Pattern
ATarget.Pattern = KpiPattern.DecreasingIsBetter;
// Banding Method
Banding TargetBanding = new Banding();
TargetBanding.Type = BandType.Normalized;
TargetBanding.ActualWorst = 999M;
TargetBanding.SpreadMinimum = 0M;
TargetBanding.SpreadMaximum = 1.2M;
TargetBanding.CustomBoundary.Add(0.1M);
TargetBanding.CustomBoundary.Add(0.2M);
ATarget.Banding = TargetBanding;
ATarget.IndicatorId = new Guid(“70b22c72-6523-487d-ae4a-ad607431584f”);
ATarget.IsCustomCurrentFormula = true; // If true, then CurrentFormula is used to compute the current value.
//ATarget.CurrentFormula = “————–MDX Formula Goes Here ————-“;
ATarget.CurrentFormula = “0”;
kpi_wows.Targets.Add(ATarget);
//Adding Description
kpi_wows.Description.Text = “This is a kpi created by the object model”;
// Assigning Permissions
Microsoft.PerformancePoint.Scorecards.Membership AdministratorMembership = new Microsoft.PerformancePoint.Scorecards.Membership();
AdministratorMembership.Login = @”Server\Administrator”;
AdministratorMembership.Role = “Editor”;
Microsoft.PerformancePoint.Scorecards.Membership ReaderMembership = new Microsoft.PerformancePoint.Scorecards.Membership();
ReaderMembership.Login = @”Server\ayman_elhattab”;
ReaderMembership.Role = “Reader”;
kpi_wows.Memberships.Add(AdministratorMembership);
kpi_wows.Memberships.Add(ReaderMembership);
// Assigning the Responsible Person
kpi_wows.Owner.Login = @”Server\Administrator”;

// publishing the KPI
Publisher.CreateKpi(kpi_wows);
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s