I need first three largest value column name in data table .except first row and totel.
for this datatable example…
| month | aaa | bbb | ccc | ddd | eee | fff | ggg | Total |
|---|---|---|---|---|---|---|---|---|
| jan | 13 | 65 | 27 | 5 | 14 | 48 | 44 | 216 |
| feb | 13 | 2 | 5 | 14 | 35 | 69 | ||
| mar | 1 | 1 | ||||||
| Total | 26 | 67 | 32 | 19 | 14 | 84 | 44 | 286 |
I need first three largest value column name in data table .except first row and totel.
for this datatable example…
| month | aaa | bbb | ccc | ddd | eee | fff | ggg | Total |
|---|---|---|---|---|---|---|---|---|
| jan | 13 | 65 | 27 | 5 | 14 | 48 | 44 | 216 |
| feb | 13 | 2 | 5 | 14 | 35 | 69 | ||
| mar | 1 | 1 | ||||||
| Total | 26 | 67 | 32 | 19 | 14 | 84 | 44 | 286 |
Try this
result = YourDataTableVariable.AsEnumerable().Select(Function(row) YourDataTableVariable.Columns.Cast(Of DataColumn)().OrderByDescending(Function(col) If(IsNumeric(row(col)), Convert.ToDouble(row(col)), Double.MinValue)).First().ColumnName).ToList()
columnNames = String.Join(",", result)
Cheers!!
OutputColumnNameString = String.Join(", ",
dataTable.Columns.Cast(Of DataColumn)()
.Where(Function(col) col.ColumnName <> "Total")
.OrderByDescending(Function(col) dataTable.AsEnumerable().Skip(1).Sum(Function(row) If(IsDBNull(row(col)), 0, Convert.ToInt32(row(col)))))
.Take(3)
.Select(Function(col) col.ColumnName)
.ToArray()
)
Use Invoke code
please attach example .xml file
Except row Total and column total
my expected output is fff-35, ddd-14, aaa-13
please share example xml. file