Expression columns typically compute a value based on other columns in the same row. You can also add an expression column to a table that generates an aggregate value. In the absence of a filtering expression, aggregates always compute their totals using all rows in a table. This is also true of aggregate expression columns. When you add such a column to a table, that column will contain the same value in every row, and that value will reflect the aggregation of all rows in the table.
C#
DataTable sports = new DataTable("Sports"); sports.Columns.Add("SportName", typeof(string)); sports.Columns.Add("TeamPlayers", typeof(decimal)); sports.Columns.Add("AveragePlayers", typeof(decimal), "Avg(TeamPlayers)");
sports.Rows.Add(new Object[] {"Baseball", 9}); sports.Rows.Add(new Object[] {"Basketball", 5}); sports.Rows.Add(new Object[] {"Cricket", 11});
MessageBox.Show((string)sports.Rows[0]["AveragePlayers"]); // Displays 8.3... MessageBox.Show((string)sports.Rows[1]["AveragePlayers"]); // Also 8.3...