Extract a value from a data table

Hi everyone,

I need to extract a value from a data table but the problem is that I need to find the column index and extract the value on the next rigth column.

For example:

|CLAVE SAP OK|PC1|DIAS1|PC2|DIAS2|PCT3|DIAS3|
|ZP30|100%|30|||||
|ZP60|100%|60|||||
|ZT120|100%|120|||||
|ZT14|15%|30|85%|30|||
|ZT15|50%|30|50%|164|||
|ZT16|15%|120|45%|95|40%|90|
|ZT18|50%|30|50%|110|||
|ZT19|20%|30|80%|90|||
|ZT20|15%|30|85%|171|||
|ZT21|20%|30|80%|120|||
|ZT22|10%|30|65%|120|25%|120|
|ZT23|50%|120|50%|120|||

Need to find the value ZT20 and extract the value at this row at the right of the 85%, the problem is that the percentages always change.

Any ideas to solve this ??

Hi,

Do you want to extract value of DIAS2 in DataRow which has “ZT20”?

If so, the following will help you.

dr = dt.AsEnumerable.Where(Function(r) r("CLAVE SAP OK").ToString="ZT20").FirstOrDefault

Sample
Sample20240808-1.zip (3.1 KB)

Regards,

That’s right but I need to find the column that has 85% because previously I store that value in a variable, because I have to do it with every percetanje that I could find.

Can you clarify a way to identify target row?
There are multiple rows which has 85% in PC2 column.

Sure the target row could be the one of has the value on the first column like ZT20 and I need to extract the value of column 4 ‘171’ but the way that I could find this value is with the percentage on the left column, that clear ??

Hi,

if i understand your requirement correctly, the following will help you.
You can change search value to modify pc2value variable.

dr = dt.AsEnumerable.Where(Function(r) r("CLAVE SAP OK").ToString="ZT20" AndAlso r("PC2").ToString=pc2Value).FirstOrDefault

Sample
Sample20240808-1 (2).zip (3.1 KB)

Regards,

But I can’t trust on the column name because it always changes or is not in the same order so I have to find the column index of the percentage for example 85% and extract the value at the next column

All right. Is “CLAVE SAP OK” column stable? If so, how about the following?

Sample
Sample20240808-1 (3).zip (3.5 KB)

Regards,

Yeah the column CLAVE SAP OK is always in the same, thanks for your help Yoichi it works

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.