DataGrids and Calculations

Here is a tough one.  I have some data that is going into a datagrid via DATASETS.  I need to Grab 3 totals.
The final total I already have using this code.
        Dim x
        If DsOtherInc1.tblotherinc.Rows.Count > 0 Then
            x = dgotherinc.DataSource.compute("SUM([Brw Amount])", 1 = 1)
            txtTTLOthInc.Text = x
        End If
The other 2 totals are based off a different colum.
If colum "B" = Include Sum Column "C" of Includes only
If colum "B" = Exclude Sum Column "C" of Excludes only.

Example of what I am trying to say.

A               b                   c
File1        Include           10.00
File2        Include           20.00
File3       Exclude           10.00

Total 1 = 40.00
Total Include = 30.00
Total Exclude = 10.00

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You use a similar method to your existing code, but with a filter on the column containing the "Include/Exclude" value.  On these lines

            y = dgotherinc.DataSource.compute("SUM([Brw Amount])", "Colb = 'Include'")


            z = dgotherinc.DataSource.compute("SUM([Brw Amount])", "Colb = 'Exclude'")


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
danormeAuthor Commented:
Well, I am close, but not there yet.  Here is my code and here is the error?

        If DsDebts1.tbldebts.Rows.Count > 0 Then
            varCalcInclude = dgDebts.DataSource.compute("Sum([monthpay])", "[action]='Include'")
            varCalcExclude = dgDebts.DataSource.compute("Sum([monthpay])", "[action]='Exclude'")
            txtInclude.Text = varCalcInclude
            txtExclude.Text = varCalcExclude
            txtDebtTtl.Text = varCalcInclude + varCalcExclude
        End If

An unhandled exception of type 'System.Data.DataException' occurred in microsoft.visualbasic.dll

Additional information: Invalid usage of aggregate function Sum() and Type: String.
What that error message appears to be saying is that the [monthpay] column on which you are trying to use the Sum() function is of String datatype rather than a Numeric datatype.  Does that ring any bells with you?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.