Identify Item in Data Table

Hello Team,

Example
We have an array suppose
data_classified={“Tomato”,“Lettuce”,“Cauliflower”}

And a Excel file read as data table dt_Exceldata as Below

dt_Exceldata contains

How can we identify
1.Item present in array and in data table column

2.Then we print the column name for each array item individually

3.Then once all items are done then print all distinct column names together
Example in this case Output would be

Leafy Greens+Night Shades +Other Vegetables

Attached Example file
Sample test.xlsx (5.0 KB)

Thanks team in advance

Hi @anmita

Check the below xaml:

Main.xaml (10.8 KB)

Hope it helps!!

Hi @anmita

This can be solved by LINQ query…
String combinedColumnName = String.Join(“,”,(dt_inputData.Columns.Cast(Of DataColumn)().
Where(Function(col) dt_inputData.AsEnumerable().
Any(Function(row) listOfNames.Contains(row(col).ToString()))).
Select(Function(col) col.ColumnName)).ToList)

dt_inputData is the Excel Data
listOfNames is the array of names

Hope this helps…
Thank You

1 Like

Ther are several options available in order to model the use case. Part2 is inserting some modelling contraints

PART2 - Lookup Dictionary Creation

Assign activity:
dictLK | DataType: Dictionary(Of String, String() =

(From c In dtData.Columns.Cast(Of DataColumn)
Let cn = c.ColumnName 
Let cia = dtData.AsEnumerable.Select(Function (x) If(isNothing(x(cn)), "", x(cn).toString.Trim))
Let ftl = cia.Intersect(data_classified).Select(Function (x) Tuple.Create(x,cn))
From t In ftl
Group t By k1=t.item1 Into grp=Group
Let cl = grp.Select(Function (gt) gt.Item2).Distinct().toarray
Select tr= Tuple.Create(k1,cl)).toDictionary(Function (t) t.Item1, Function (t) t.Item2)

Part3
we can use the dictLK from Part 2

Assign activitiy
arrColNames | DataType: String Array =

dictLK.Values.SelectMany(Function (x) x).Distinct().ToArray

Visualizations:

Test Variation - bring one item into more Columns

So Code was handling this

Hi @anmita , here’s a pure UiPath solution. Hopefully this is easy to follow and learn.

image

Thanks @Parvathy , @ppr , @sudster and @Sanjay_Bhat for the detailed responses

1 Like

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