Eric Bryan

Eric Bryan

  • 1.9k
  • 18
  • 2.4k

Cannot get sum from Dataview list

Jul 31 2020 2:41 PM
Hello everybody,
I try to get a list from a dataview containing a sum and grouped by some fields.
  1. DataView view = _objManager.ACCOUNTS.DefaultView;  
  2. // Set RowStateFilter to display the current rows.  
  3. view.RowStateFilter = DataViewRowState.CurrentRows;  
  4.   
  5. var res = ((DataTable)view.Table)  
  6. .AsEnumerable()  
  7. .GroupBy(row => new { ID = row.Field<long?>("ID"), ELEM = row.Field<string>("ELEM") })  
  8. .Select(sel => new  
  9. {  
  10. NAME = sel.First()["NAME"],  
  11. ID = sel.First()["ID"],  
  12. IBAN = sel.First()["IBAN"],  
  13. BIC = sel.First()["BIC"],  
  14. INFO = sel.First()["INFO"],  
  15. AMOUNT= sel.Sum(s => sel.Sum()["AMOUNT"]) //doesn't work  
  16. }).ToList();  
But the sum doesn't compile.
Do you have and idea ?
Thanks a lot in advance.
Eric

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (6)