How to find the specific value count in excel using LINQ

Hi Team,

I want to find today date count in each rows once found today date in anyone row then check the count of today date if today date count is 4 then skip that row , if today date count is less then 4 like count 1 or 2 or 3 then pick the first index value in particular row then print the log message and update Today date to last index of row in particular row.

Should update one row only based on input “L1” column, If i give input YYY check max count of 4 today date, if present then skip that row, else update today date, based upon the input first column.

if XXX i give input means check max count of today date if less than 4 today date then update today date .

Please anyone help me for this.

Input:

Output:

Regards,
Raja G

HI USERS ,
Please refer below topic :slight_smile:

Thanks
HAPPY AUTOMATION ‘’’

1 Like

Hi @anon87560229 ,

Im looking for row like below,

input file:

Please help me @supermanPunch @ppr

Hi @Raja.G,

What about this workflow

Input

Output

Workflow

LinQ

(From row In dt.AsEnumerable
Let a = System.Text.RegularExpressions.Regex.Matches(String.Join(",",row.ItemArray),"\b\d{2}\.\d{2}\.\d{2}\b").ToList()
Let b = a.Where(Function(x) x.ToString.Equals(Now.ToString("MM.dd.yy"))).ToList().Count=4
Let c = If(b,String.Join(",",row.ItemArray).Split(CChar(",")),(String.Join(",",(String.Join(",",row.ItemArray)).Split(",",StringSplitOptions.RemoveEmptyEntries))+",Output "+Now.ToString("MM.dd.yy")).Split(CChar(",")))
Select dt.Clone.Rows.Add(c)).CopyToDataTable

Thanks,
Rajkumar

1 Like

Hi @RajKumar_DC ,

Thanks, This is not static table , You mention Add data column in “L9”, Where ever occur in today date based upon input name that particular row only should update.

Based on first column(“L1”), If i give XXX that row only should process check max count 4 if 4 than should skip else update that row.

Regards,
Raja G

Hi @Raja.G ,

Now i have added “d” value in query and pass your Key value via stKey check below workflow

Workflow

Code:

(From row In dt.AsEnumerable
Let a = System.Text.RegularExpressions.Regex.Matches(String.Join(",",row.ItemArray),"\b\d{2}\.\d{2}\.\d{2}\b").ToList()
Let b = a.Where(Function(x) x.ToString.Equals(Now.ToString("MM.dd.yy"))).ToList().Count=4
Let c = If(b,String.Join(",",row.ItemArray).Split(CChar(",")),(String.Join(",",(String.Join(",",row.ItemArray)).Split(",",StringSplitOptions.RemoveEmptyEntries))+",Output "+Now.ToString("MM.dd.yy")).Split(CChar(",")))
Let d = If(row.ItemArray(0).ToString.Equals(stKey),c,row.ItemArray)
Select dt.Clone.Rows.Add(d)).CopyToDataTable

Output

Thanks,

@RajKumar_DC ,

What should i add in “Column Name” for Add Data Column activity?

Regards,
Raja G

Hi @Raja.G ,

before i was taken via Index based, now i used column name change the ‘d’ value below

(From row In dt.AsEnumerable
Let a = System.Text.RegularExpressions.Regex.Matches(String.Join(",",row.ItemArray),"\b\d{2}\.\d{2}\.\d{2}\b").ToList()
Let b = a.Where(Function(x) x.ToString.Equals(Now.ToString("MM.dd.yy"))).ToList().Count=4
Let c = If(b,String.Join(",",row.ItemArray).Split(CChar(",")),(String.Join(",",(String.Join(",",row.ItemArray)).Split(",",StringSplitOptions.RemoveEmptyEntries))+",Output "+Now.ToString("MM.dd.yy")).Split(CChar(",")))
Let d = If(row("L1").ToString.Equals(stKey),c,row.ItemArray)
Select dt.Clone.Rows.Add(d)).CopyToDataTable
1 Like

Hi @RajKumar_DC ,

I got below exception please help me on this

Main.xaml: Compiler error(s) encountered processing expression “(From row In dt_data.AsEnumerable
Let a = System.Text.RegularExpressions.Regex.Matches(String.Join(”,“,row.ItemArray),”\b\d{2}.\d{2}.\d{2}\b").ToList()
Let b = a.Where(Function(x) x.ToString.Equals(Now.ToString(“MM.dd.yy”))).ToList().Count=4
Let c = If(b,String.Join(“,”,row.ItemArray).Split(CChar(“,”)),(String.Join(“,”,(String.Join(“,”,row.ItemArray)).Split(“,”,StringSplitOptions.RemoveEmptyEntries))+“,Output “+Now.ToString(“MM.dd.yy”)).Split(CChar(”,”)))
Let d = If(row(“L1”).ToString.Equals(stKey),c,row.ItemArray)
Select dt_data.Clone.Rows.Add(d)).CopyToDataTable".
‘ToList’ is not a member of ‘System.Text.RegularExpressions.MatchCollection’.

Regards,
Raja G
Excel_columindex_linq.zip (2.5 KB)

@Raja.G
we would recommend to start with essential / hybrid LINQ approach to do a first prototype:
Find below some starter help for the main building blocks

For each activity: set typeargument to DataRow -

item in dtData.AsEnumerable.Where(Function (x) x("L1").toString.Trim.Equals(YourFilterStringVar))

we can do on string base:
item.ItemArray.Skip(1).Where(Function (x) x.toString.Contains(“YourDateStringVar”)).Count

get the index

item.ItemArray.ToList.FindIndex(Function (x) IsNothing(x) OrElse String.IsNullorEmpty(x.toString.Trim))

Hi @ppr,

If you have xmal na, Please send me.

Regards,
Raja G

Hi @Raja.G,

Check this attached

JanTest-2023.7z (140.8 KB)

Thanks,

Hi @RajKumar_DC ,

I couldn’t able to open 7z file ,please share compress Zip file or direct xmal

Regards,
Raja G

Plz check this Xaml

Sequence1.xaml (7.6 KB)

Not opened

Hi @Raja.G,

may i know your studio version ?

@RajKumar_DC ,

2022.4.0

Hi @Raja.G,

Try this

(From row In dt_data.AsEnumerable
Let a = String.Join(",",System.Text.RegularExpressions.Regex.Matches(String.Join(",",row.ItemArray),"\b\d{2}\.\d{2}\.\d{2}\b")).Split(CChar(",")).ToList
Let b = String.Join(",",a.Where(Function(x) x.ToString.Equals(Now.ToString("MM.dd.yy")))).ToList().Count=4
Let c = ((String.Join(",",row.ItemArray)).Split(",".ToCharArray,StringSplitOptions.RemoveEmptyEntries)).toarray()
Let d = If(row("L1").ToString.Equals(str_Name),c,row.ItemArray)
Select  dt_data.Clone.Rows.Add(c)).CopyToDataTable

Thanks,

Hi @RajKumar_DC ,

Update on empty cell not happened please check this

Today date not update in respective place , i attached excel also.

Excel_columindex_linq.zip (10.8 KB)

Regards,
Raja G