Split Csv file into multiple files according to month in date column

Hi Team,

I need your help. Please have a look into below question.

I have a csv file with 6 columns. Out of which one column named “Date” is having multiple rows with dates in mm/dd/yyyy(7/1/2021) format(I am not sure if format will change in future). I am reading the csv and storing it in a datatable. so now the date column format has changed to yyyy/mm/dd after using “read csv” activity. And the column type is string.
Requirement : I have to split the csv file into multiple files as per Month. for example if there are 3 months data in that column, then i need to split the whole file into 3 files accordingly. Then i need to upload those files somewhere.
I was able to get the solution but still need some inputs from you all for the best solution.

Thank you.

@Diva_P
Welcome to the forum

we can do it with help of GroupBy

As a starter help:

Assign activity:
leftSide: TableList | DataType: List(Of DataTable)
Right side:

(From d in YourDataTableVar.AsEnumerable
Group d by k= CDate(d(“Date”)).Month into grp=Group
Select t=grp.CopyToDataTable).toList

For Each Activity (NOT for each row) | TypeArgument: DataTable item in TableList

  • write out month split excel to Excel - e.g. with write excel
1 Like

Thank you so much @ppr
I am able to get my expected solution now.

Just one more thing. If i want to write each datatable to csv with the month name(for example june/july as per data) along with the file path then how to do that. Please refer the attachment.

image

give a try on CDate(DataTable.Rows(0)(“Date”).toString.Trim).toString(“MMMM”)

1 Like

It worked. Thanks a lot @ppr for your Time…

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