Excel: Need to Filter The rows

HI Team,

I have a DT and need to filter the DT and by value of rows.
DT is look like below.

Template Name Name First Name Last Name City
Test Yes Yes No Yes

If Test value was Yes we have to Keep that columns and columns names I need.

How to do? Can any one give the solution please.

Thanks,
Chethan P

Hi @copy_writes

Can you try below Query

filteredColumns  = String.Join(", ", DT.Columns.Cast(Of System.Data.DataColumn)().
                                            Where(Function(col) DT.AsEnumerable().
                                            Any(Function(row) row("Template Name").ToString() = "Test" AndAlso row(col.ColumnName).ToString() = "Yes")).
                                            Select(Function(col) col.ColumnName))

Regards,

What is variable type?

@copy_writes

String

Regards,

Is that Possible to Keep it in the Array format

Yes, How about the following?

DT.Columns.Cast(Of System.Data.DataColumn)().
                           Where(Function(col) DT.AsEnumerable().
                           Any(Function(row) row("Template Name").ToString() = "Test" AndAlso row(col.ColumnName).ToString() = "Yes")).
                           Select(Function(col) col.ColumnName).ToArray()

Output:

The image shows an output log from a process execution with specific fields highlighted, including "Name," "First Name," and "City." (Captioned by AI)

Regards,

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