Get week periods based on two data table columns dates

Input DT :
DT_Input.xlsx (10.4 KB)

We need to get the week periods based on Termination Date and Logon date.

Requirement 1 :

If logon date is on or before Termination Date or Logon Column contains “not in use” then update the “Status” Column as “To be Deleted”

Requirement 2 :

If logon date is after Termination Date

Then update the all the week periods coming between termination date and logon date in comma separated.

Ex : Termination Date : 07-07-2024 00:00:00 & Logon Date 07/14/2024

Expected value in Week periods column is

image

And then update the “Status” Column as “LogsRequired”

Expected output
ExpectedOutput.xlsx (10.5 KB)

Hi @Sathish_Kumar_S

You can use the LINQ Expressions to get the required data, Follow the below steps,
→ Use the Read range workbook activity to read the excel and store in a datatable called Input_dt.
→ Then use the assign activity and write the below LINQ Expression,

- Assign -> Output_dt = (From row In Input_dt.AsEnumerable()
                         Let TerminationDate = CDate(row("Termination Date"))
                         Let Bool_workperiods = If(row("Logon").ToString().Equals("not in use"), False, If(CDate(row("Logon")) > TerminationDate, True, False))
                         Let weekperiods = If(Bool_workperiods, TerminationDate.AddDays(-(TerminationDate.DayOfWeek + 6) Mod 7).ToString("MM/dd/yyyy") & "-" & TerminationDate.ToString("MM/dd/yyyy") & ", " &  CDate(row("Logon")).AddDays(-(CDate(row("Logon")).DayOfWeek + 6) Mod 7).ToString("MM/dd/yyyy") & "-" & CDate(row("Logon")).ToString("MM/dd/yyyy"), "")
                         Let Status = If((Bool_workperiods.equals(False)), "To be Deleted", "LogRequired")
                         Select Input_dt.Clone.Rows.Add({row("UserID").ToString(), row("Logon"), TerminationDate.ToString("MM/dd/yyyy"), weekperiods, Status})
                             ).CopyToDataTable()

→ Then use the write range workbook activity to write the Output_dt to the Excel file.

Check the below workflow for better understanding,
Sequence2.xaml (13.8 KB)

Sheet2 has output data in the below excel file,
DT_Input.xlsx (10.6 KB)

Hope it helps!!

we suggest to divide and conquer.

For updating column value options have a look here:
How to Update Data Column Values of a Data Table | Community Blog

And would also recommend check deeply if a LINQ approach for column value updating is the approach which will fit to your situation (skill set, maintenance tasks…)

With the division of the different subtasks, row looping, the filtering and general updating should be well known by you and be fine.

So, we would focus on the week period calculations and suggest to clear the details.

  • is Termination Date always a Sunday?
  • Line 4: 15-23 July, is this span not split into weeks and how to handle remaining fractions?

Thank you for your solution… sorry not getting the expected output

Here is the expected output

User2 is Termination Date & Logon date comes under week27 …but getting different week period ( when the termination & logon date falls between only one week then week period contains only that week numbers period)

User3 dates comes under week 28 & 29… getting correct week period for week 28… but is different for week 29

Also is it possible to add backward slash before every forward slash in the week period?

Attached excel sheet with input and expected output:
Output1.xlsx (9.5 KB)

Here is the reason why we need to week period in this format

Bot needs to click required week periods for the terminated users and get logs in SAP

image

Selector :

Can you be more specific what is week period is… @Sathish_Kumar_S

How we have to calculate the week period, that was more confusing.

Please refer this link for week periods : Week Numbers for 2024

User 2 is termination date on July 1 and logon date is July 6 so the expected week period is 07/01/2024-07/07/2024 ( week number 27 )

User 3 is termination date on July 14 and logon date is July 20 , so the expected week period is 07/08/2024-07/14/2024, 07/15/2024-07/21/2024 ( week number 28 & 29)

Please refer my requirement below… the termination date is not always sunday… Can you guide?

Here is the expected output

User2 is Termination Date & Logon date comes under week27 …but getting different week period ( when the termination & logon date falls between only one week then week period contains only that week numbers period)

User3 dates comes under week 28 & 29… getting correct week period for week 28… but is different for week 29

Also is it possible to add backward slash before every forward slash in the week period?

Attached excel sheet with input and expected output:
Output1.xlsx (9.5 KB)

Here is the reason why we need to week period in this format

Bot needs to click required week periods for the terminated users and get logs in SAP

image

Selector :

Please refer this link for week periods : Week Numbers for 2024

User 2 is termination date on July 1 and logon date is July 6 so the expected week period is 07/01/2024-07/07/2024 ( week number 27 )

User 3 is termination date on July 14 and logon date is July 20 , so the expected week period is 07/08/2024-07/14/2024, 07/15/2024-07/21/2024 ( week number 28 & 29)

a few things could be better defined. However, we still recommend applying

Weeknumber retrieval:
grafik

So we can

  • calculate from both dates the corresponding start Monday and end Sunday
  • setting up a series dates / filtering on Monday/Saturday
  • grouping it on Weeknumber / Chunking on filtered Series
  • Creating the weekspan strings

Examples (also Have a look at the modify date Activity:
Getting the Monday from any given date:
grafik

Getting a Sunday from any given date
grafik

Creating the Series:

From this series we can create the week spans as needed

about / formats:


kindly note: we escaped a \ with another one

1 Like

Is it possible to share the XAML file contains above activities?

all snippets shown in the immediate panel
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

can be modeled by you e.g. using an assign activity

1 Like