How to calculate and write data in new excel sheet

Hello,

we have on eexcel with 2 sheets like below.
In sheet 1 , suppose there are 2 users and those are tagged in 2 pojects(DC500,DC400) / 1 project(DC100) that data is there like below.

In sheet 2 unique data is there with no duplicate value with reference to sheet 1 , like below

my expected output is ,

first need to add two column like project key and total hours with keeping same data as sheet 2
then for each user need to check is he tagged in more than one project or not ,
if no then -
need to add data i column “worked” and write to “total hours” in new sheet , here rohit worked in only 1 project so in output sheet in 1 row data is there with woked column total in total hours

If yes then (worked more than 1 project)-
need to add that many rows for user with respect to projects and need count of worked intotal hours.
here kunal worked in 2 projects so count for first project for hours is 10+10 =20 and for second project is 2 so same mentiioned in output excel

how can i achieve this?

Hello @Mathkar_kunal,

Read both sheets into DataTables (dtSheet1 for detailed data and dtSheet2 for unique users), then add two new columns, Project Key and Total Hours, to dtSheet2. For each user in dtSheet2, filter dtSheet1 to get all rows for that user; if the user is linked to only one project, add a single row with the project key and the total of their Worked hours, but if the user is linked to multiple projects, create a separate row for each project and calculate the Total Hours by summing the Worked values for that specific project. Finally, write the result into a new output sheet.