i have an excel file, Mrkt Comments Column have some string like 06/11/2024_Claim denied for invalid DX code so claim escalated to GEI team for further assistance Claim #66116598…SS
i already extracted date from the string and apply a condition on the date because i need only that date from the string which lie in between last 30 to 45 days old only from current date and i find that dates in my op variable like if date is 06/07/2024 then op= 06/07/2024 and if date 05/04/2024 then op= blank, now i want a linq code if op value have match with Mrkt Comments column value then keep the whole row and if op= blank then delete the whole row from data table
Thanks in advance
dt = dt.AsEnumerable()
.Where(Function(row) Not String.IsNullOrEmpty(op) AndAlso row("Mrkt Comments").ToString.Contains(op))
.CopyToDataTable()
i apply this linq code there but this is not work,
If(String.IsNullOrEmpty(op), dt3.Clone(), (From r In dt3.AsEnumerable() Where r.Field(Of String)(“Mrkt Comments”).Contains(op) Select r).CopyToDataTable())
Hi @Arvind1
Could you share the input and expected output file for our better understanding.
If you don’t have the Confidential data then make the data dummy and share it with us.
Is my above linq query works for you,if not please share the input sample file and expected output also
get the error –
Assign: The source contains no DataRows.
Please Share the Input sample and expected Output.
Might be Your datatable doesn’t contain any data that’s why it was throwing error… @Arvind1
Check the datatable contains any data or not
Book1.xlsx (9.4 KB)
this is my excel
check
Book1.xlsx (9.4 KB)
This is input file
Book1.xlsx (10.3 KB)
expected output in sheet2
based on mrkt comments if date 30-45 older than current date then keep the whole row otherwise delete the whole row
Thanks
Hi @rlgandu
Book1.xlsx (10.3 KB)
expected output in sheet2
based on mrkt comments if date 30-45 older than current date then keep the whole row otherwise delete the whole row
Thanks
Okay @Arvind1
You can use the below LINQ Expression,
→ Use the Read range workbook activity to read the excel and store in a datatable called Input_dt.
→ Then create a datatable datatype variable called Output_dt and take an assign activity to write the below LINQ Expression,
- Assign -> Output_dt = (From row In Input_dt
Let DateVar = DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(row("Mrkt Comments").ToString(), "\d+\/\d+\/\d{4}").Value, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)
Where DateVar >= DateTime.Now.AddDays(-45) AndAlso DateVar <= DateTime.Now
Select row
).CopyToDataTable()
→ Then use the write range workbook activity to write the Output_dt to the excel.
Check the below workflow for better understanding,
Sequence5.xaml (13.6 KB)
Check the below excel file, the output is in Sheet3,
Book1 (1).xlsx (11.0 KB)
Hope it helps!!
getting the error- Write Range Workbook: Object reference not set to an instance of an object.
error in write range workbook
Can you try my approach
Might be the Output_dt not contain any data with init… @Arvind1
Can you debug the flow and see the Output_dt output in immediate panel.
Hi lakshmi,
yes, try , but receive the errr like–Invoke Code: Exception has been thrown by the target of an invocation. what is this
yes, you are right, output dt not contain any data, but there are so many data based on the date condition