I am trying to do a simple financial table that compares the actual to the budgeted figures and show the variance.
**Actual**
ID Revenue
1 100
2 120
**Budget**
ID Revenue
1 120
2 100
Once compared it will give me this table:
**Variance**
ID Revenue
1 -20
2 +20
This is how I got my two tables setup right now:
// Make the Actual table
DataTable allActual = new DataTable("actualTable");
DataRow rowActual;
// Create columns and add to the DataTable.
allActual.Columns.Add("Title", typeof(string));
allActual.Columns.Add("Revenue", typeof(string));
// Add rows to the Actual grid
foreach (SPListItem item in actualItems)
{
rowActual = allActual.Rows.Add();
rowActual["Title"] = item["Title"].ToString();
rowActual["Revenue"] = item["Revenue"].ToString();
}
// Make the Budget table
DataTable allBudget = new DataTable("budgetTable");
DataRow rowBudget;
// Create columns and add to the DataTable.
allBudget.Columns.Add("Title", typeof(string));
allBudget.Columns.Add("Revenue", typeof(string));
// Add rows to the Actual grid
foreach (SPListItem item in budgetItems)
{
rowBudget = allBudget.Rows.Add();
rowBudget["Title"] = item["Title"].ToString();
rowBudget["Revenue"] = item["Revenue"].ToString();
}
I would appreciate any help in pointing me to the right answer. Thanks.
You could use LINQ-To-DataSet to get the difference:
Edit: Here is the C# version of the Dictionary-approach(use a simple
ToListto get a list of this anonymous type):VB.NET:
Or create a Dictioary(Of Int32, Int32) if you want to lookup a difference for a given ID: