4

I'm trying to get the average P&L in a column. The column is of type double, however I keep getting an error saying the following:

Additional information: Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier.

This occurs when this line is executing:

avgFiveSbefore = (double)dt.Compute("AVG(5sBeforePnL)", "");

Also, here's some additional code to clarify:

dt.Columns.Add(Columns.FiveSecBeforePnL, typeof(double));

foreach(DataRow row in dt.Rows)
{
  row[Columns.FiveSecBeforePnL] = some value;
}

double avgFiveSbefore;
avgFiveSbefore = (double)dt.Compute("AVG(5sBeforePnL)", "");
1
  • Could you try changing the column name to something that doesn't start with a number? Just thinking that might be the cause. Commented Feb 25, 2014 at 18:49

1 Answer 1

9

Try enclosing the column name in square brackets.

avgFiveSbefore = (double)dt.Compute("AVG([5sBeforePnL])", "");

You can also use LINQ to do the same like:

double avgFiveSbefore = dt.AsEnumerable()
                            .Average(r =>
                                r.Field<double>(Columns.FiveSecBeforePnL));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.