Extract max value the two columns

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<br/>
Good morning,<br/>
<br/>
Im trying to apply a simple way to solve a small problem, but I am not able to solve.<br/>
<br/>
I am using the following data table<br/>
<br/>
<br/>
row<span style="white-space:pre Num<span style="white-space:pre
Item<span style="white-space:pre Count<span style="white-space:pre
Item1<span style="white-space:pre Item2<br/>
1<span style="white-space:pre 2<span style="white-space:pre A,B<span style="white-space:pre
40<span style="white-space:pre A<span style="white-space:pre
B<br/>
2<span style="white-space:pre 2<span style="white-space:pre E,H<span style="white-space:pre
30<span style="white-space:pre E<span style="white-space:pre
H<span style="white-space:pre <br/>
3<span style="white-space:pre 2<span style="white-space:pre A,E<span style="white-space:pre
20<span style="white-space:pre A<span style="white-space:pre
E<br/>
4<span style="white-space:pre 2<span style="white-space:pre F,G<span style="white-space:pre
20<span style="white-space:pre F<span style="white-space:pre
G<br/>
5<span style="white-space:pre 2<span style="white-space:pre A,D<span style="white-space:pre
10<span style="white-space:pre A<span style="white-space:pre
D<br/>
6<span style="white-space:pre 2<span style="white-space:pre A,C<span style="white-space:pre
10<span style="white-space:pre A<span style="white-space:pre
C<br/>
7<span style="white-space:pre 2<span style="white-space:pre E,B<span style="white-space:pre
10<span style="white-space:pre E<span style="white-space:pre
B<br/>
8<span style="white-space:pre 2<span style="white-space:pre B,D<span style="white-space:pre
10<span style="white-space:pre B<span style="white-space:pre
D<br/>
9<span style="white-space:pre 2<span style="white-space:pre B,C<span style="white-space:pre
10<span style="white-space:pre B<span style="white-space:pre
C<br/>
<br/>
<br/>
the goal is to store another table the row where the value with item appears more often.<br/>
<br/>
The problem is that I must be doing something wrong where I can not identify the line<br/>
<br/>
<br/>
Dictionary<string, Items> list_max = new Dictionary<string, Items>();<br/>
foreach (Items s in List_Initial)<br/>
{<br/>
string val_item = s.Item;<br/>
double max = 0;<br/>
<span style="white-space:pre cont=2;<br/>
for (int a = 1; a < cont; a++)<br/>
{<br/>
<br/>
string expression = "item" + a +"=" +val_item +"";<br/>
DataRow[] foundRows;<br/>
<br/>
// Use the Select method to find all rows matching the filter.<br/>
foundRows = _tab_resul.Select(expression);<br/>
<br/>
DataTable temp = new DataTable();<br/>
temp = foundRows.CopyToDataTable();<br/>
var maxRow = temp.Select("item" + a +"= MAX(" + "item" + a +")");<br/>
<br/>
}<br/>
<span style="white-space:pre }<br/>
<br/>
<br/>
Item B for example, appears on lines {1,7,7,8}, but what I save in another table is the the resukts in line 1.<br/>
<br/>
this process for all items<br/>
<br/>
Thanks

View the full article
 

Similar threads

A
Replies
0
Views
161
ANIL AYDINALP
A
D
Replies
0
Views
103
Donald Uko
D
R
Replies
0
Views
87
Rosemerysalvedora
R
Back
Top