15,353,818 members
0.00/5 (No votes)
See more:
Hi All

Below is the data i have in excel
```Server Name Control Group   Tape Number Status  Transfer Start Date Transfer Start Time Transfer End Date   Transfer End Time
BR502V7C    QCLDUSYSW         Q23028    ACTIVE     25-09-2021          07:46:47            25-09-2021         08:46:40
BR502V7C    QCLDUSYSW         Q27785    ACTIVE     25-09-2021          07:46:47            25-09-2021         08:46:41
BR502V7C    QCLDUUSRD         Q26071    ACTIVE     24-09-2021          21:02:58            24-09-2021         21:04:47
BR502V7C    QCLDUGRPD         Q27657    ACTIVE     24-09-2021          21:06:45            24-09-2021         21:16:04
BR502V7C    QCLDUIPLW         Q17404    ACTIVE     25-09-2021          07:46:47            25-09-2021         07:55:49
BR111V11    ABCDEFGH          Q00000    ACTIVE     24-09-2021          01:06:45            24-09-2021         02:16:04
BR111V11    ABCDEFGH          Q9999     ACTIVE     25-09-2021          07:46:47            25-09-2021         07:55:49```

I need to calculate the MIN and MAX values for Transfer Start Time (F) and Transfer End Time(H)

and put data like below in same excel at Sheet1

```System Name Start Date  Start Time  End Date    End Time    "Total Duration(HH:MM:SS)"
BR502V7C    25-09-2021  07:46:46    25-09-2021  21:16:04    13:29:18
BR111V11    24-09-2021  01:06:45    24-09-2021  07:55:49    06:49:04```

What I have tried:

e.g. for 1 server

```Start Time=MIN(Sheet2!F2:F6)
End Time=MAX(Sheet2!H2:H6)
Total Duration(HH:MM:SS)=E2-C2```

Need help in how to do this
Posted
Updated 6-Oct-21 6:57am
Comments
CHill60 6-Oct-21 11:47am

And what is wrong with the way you have done it?
Empty Coder 6-Oct-21 12:10pm

I am not aware not to do excel calculations in powershell
Richard MacCutchan 6-Oct-21 12:22pm

As I already suggested: use Excel formulas, or write VBA macros.

Solution 1

If I was trying to find the minimum and maximum values of data in Excel I would just use a pivot table - either a straight forward pivot or a pivot query using Power Query.

In Excel it's probably best to combine the date and time into a single column (for calc purposes - it doesn't have to be permanent). You can then just subtract one datetime from the other - see How to Calculate Elapsed Time in Excel | Excelchat[^]

It's not clear where or why Powershell comes into this - but you may find this post useful By Example – PowerShell commands for Excel | SQL Notes From The Underground[^]
Powershell (or VBA) can also be used to auto-refresh the pivot data as necessary

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 150 CPallini 70 Patrice T 50 Christian Graus 40 steveb 10
 OriginalGriff 160 CPallini 70 Patrice T 50 Christian Graus 40 steveb 10

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900