Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:26:46+00:00 2026-05-28T17:26:46+00:00

I am trying to do a simple financial table that compares the actual to

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:26:46+00:00Added an answer on May 28, 2026 at 5:26 pm

    You could use LINQ-To-DataSet to get the difference:

    Edit: Here is the C# version of the Dictionary-approach(use a simple ToList to get a list of this anonymous type):

    var diff = (from  aRow in tblActual.AsEnumerable()
                join bRow in tblBudget.AsEnumerable()
                on aRow["ID"] equals bRow["ID"]
                let aRev = (int)aRow["Revenue"]
                let bRev = (int)bRow["Revenue"]
                where aRev != bRev
                select new 
                {
                    ID = (int)aRow["ID"],
                    Diff = aRev - bRev
                }).ToDictionary(r => r.ID, r=> r.Diff );
    

    VB.NET:

    Dim diff = (From aRow In tblActual
                Join bRow In tblBudget _
                On aRow("ID") Equals bRow("ID")
                Let aRev = DirectCast(aRow("Revenue"), Int32)
                Let bRev = DirectCast(bRow("Revenue"), Int32)
                Where aRev <> bRev
                Select New With {.ID = DirectCast(aRow("ID"), Int32),
                                .Diff = aRev - bRev}).ToList
    
    
    For Each d In diff
        Dim id = d.ID
        Dim revDifference = d.Diff
    Next
    

    Or create a Dictioary(Of Int32, Int32) if you want to lookup a difference for a given ID:

    Dim diff = (From aRow In tblActual
                Join bRow In tblBudget _
                On aRow("ID") Equals bRow("ID")
                Let aRev = DirectCast(aRow("Revenue"), Int32)
                Let bRev = DirectCast(bRow("Revenue"), Int32)
                Where aRev <> bRev
                Select New With {.ID = DirectCast(aRow("ID"), Int32),
                                .Diff = aRev - bRev}).
                                ToDictionary(Function(r) (r.ID), 
                                             Function(r) (r.Diff))
    
    ' returns diff for a given ID '
    Dim diffForID2 = diff(2)
    ' iterate all dictionary entries '
    For Each d In diff
        Dim id = d.Key
        Dim revDifference = d.Value
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple Automator workflow that will prompt me for where
I'm trying a simple F# script that will find pythagoras. Here's the code: open
I am trying a simple validation program with JSP and EL (not that I
I'm working on a simple financial application using MVVM & LinqToSql. I'm trying to
I am trying a simple Keystroke command to Show All Bookmarks in Safari 5.0.2
I am learning and trying simple example using node.js and mongoskin. here is my
I am trying something simple as creating a text file and then send it
I am trying a simple Extension Method example and am unable to increment or
I am trying this simple tutorial from oracle : http://www.oracle.com/technetwork/java/socket-140484.html (the Example 1 ).
Hi I am trying out simple rollover images for a site I am currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.