Assign: Sequence contains no elements- Data Table Extracting the Latest Date in DataTable

Hi All,

I am using the below expression to find the maximum date in my data table. Currently its a single row in DataTable but at run run times it may contain multiple line items with multiple dates. I need to find the max date . But I am currently getting an error. “Assign: Sequence contains no elements”

ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r((“Date”)).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r(“Date”).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString(“MM-dd-yyyy”)

Thanks in Advance

Hi,

Your expression seems no problem. Can you check (share) content of DataTable? Please set Breakpoint at the activity then check it in Locals panel.

Regards,

Hi @dutta.marina ,

I believe the TryParseExact() does not work as expected, because of the format mentioned.

Check the Datatable value by Debugging the workflow. The format might be in the below way :

MM/dd/yyyy HH:mm:ss

So you might need to adjust accordingly in the Expression, maybe to the below:

ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r("Date").ToString,"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r("Date").ToString,"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString("MM-dd-yyyy")

Look for any empty Sequence activity in your project.

Hi Arpan,

I tried to debug the DataTable .The format is

@dutta.marina

as per the format please use M/d/yyyy in both parse and try parse

Also to avoid future errors it is better you use a if condition to check if atleast one row is returned from where condition

ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r("Date").ToString,"M/d/yyyy",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Count>0

on then side use the expression on else side you are not getting any rows that are matching

cheers

Hi @dutta.marina

ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r(“Date”).ToString,“M/d/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r(“Date”).ToString,“M/d/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString(“MM-dd-yyyy”)

or with M/dd/yyyyy

ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r(“Date”).ToString,“M/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r(“Date”).ToString,“M/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString(“MM-dd-yyyy”)

Try with this

Thanks @adiijaiin It worked.

Thanks @Anil_G for the solution

1 Like

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