Linq query with the found element


Can any one help with this query, i need to get the value found using data scraping, from the first found to the last found. Let’s say :

Ex : if “Corporate” found we take it if first, if not we take “Small” first, if none the two found we take the last one “Mobile”

Attached an example, but trying to do it with link query, if someone knows better, thanks !

DataTable.AsEnumerable().Where(Function(row) row(“TYPE SERVICE”).ToString.Contains(“Corporate”)).CopyToDataTable

test_corporate.xaml (12.2 KB)

may we ask to give us some more details to the requirement as a look on XAML and the LINQ still let open some questions. Maybe you also can share some sample data with us.

  • taking the column value or the datarow?
  • first? first occurence in the datatable data?

similar, what is the definition of last.

Kind regards

Hello @ppr

Thank you for your reply, in fact i can’t share the link where the data is scraped from, what i’m trying to do is similar to what i did on the xaml file, just trying to do it with the linq query.

Normaly, there’s 3 values i have to look for, but each one come first than the others, like if there’s “Corporate”, we take, only if there’s no corporate, we take the second one which is “Small”, or if none of them found, than only than we take “Mobile”.

The query i did, before, works only if there’s a value “Corporate”, i have to keep the same query, but add the conditions of the two other values.

And once done, i copy that value to a datatable, as shown on the query, but since it works only if “Corporate” exists, well if it’s not it will not work.

Hope it clear for you !

Thank you,


we learned from Santa /& Rudolf:


Advent #8

Sure we respect every confidental needs. But sample data can be created even without breaking confidental needs:
Type_SERVICE | Col2 | Col1
###Corporate | 12|A3

Have a look here:

it is a very good example on how visually and with abstract sample data the case was explained

Some sample data would really help. The mentioned above description / XAML is not razor sharp defining all requirements. (Does First mean first row, first occurence … all important requirements)

So please help us with some more details that we can work out a better fitting solution approach.

Many thanks for your support
Kind regards

Please clear scenario step by step

Hi @ppr

What i’m trying to do, is the value correspondent to one of the previous list, on a priority level.

For example :

sanss titre

Here we have “Corporate” and “Mobile”, since “Corporate” is priority, we take it, if “Corporate” wasn’t available we would take the second on list of priority, which is “Small”, since “Small” ain’t available too, we take “Mobile”, that’s what i did with the sample xaml example, but trying to simplify it with a linq query, only if possible…

Hope it’s clear for you, thank you!

i got your scenario and go thought your workflow, just you have to change for each row if condition nested put first if condition which will change corporate then put other if condition in else section of “corporate” if to check “Mobile” then in mobile else condition check “small”…

if its helpful please mark as solution