My NetWorkDays is sometimes more than the Calendar days - excel

So in my job, I am trying to find the average calendar days between two dates and average business days.
For calendar days, I am using:
=[#[DateLastInReview ]]-[#[DateTimeStamp ]]
For Business days, I am using:
=NETWORKDAYS([#[DateTimeStamp ]], [#[DateLastInReview ]], Holiday)-(1-MOD([#[DateLastInReview ]]-[#[DateTimeStamp ]],1))
They should both give me the dates to a decimal place... but my issues is sometimes the business days are higher than the calendar days. Which makes no sense. Because of how the data is being copied from excel, I had to show the time Stamp separately from date Stamp. But, they are in the same cell when using the NETWORKDAYS equation.
+----------------+---------------+-------------------+------------------+--------+--------+
| DateTimeStamp | DateStampTime | DateLastInReview | LastInReviewTime | PreCal | PreBus |
+----------------+---------------+-------------------+------------------+--------+--------+
| 2018-07-11 | 12:00 AM | 7/12/2018 | 12:00 AM | 1.00 | 1.00 |
| 2018-07-09 | 3:07 PM | 7/10/2018 | 9:42 AM | 0.77 | 0.77 |
| 2018-07-02 | 12:34 PM | 7/3/2018 | 7:45 AM | 0.80 | 1.80 |
| 2018-07-02 | 3:34 PM | 7/3/2018 | 8:06 AM | 0.69 | 1.69 |
| 2018-07-02 | 9:59 AM | 7/3/2018 | 8:06 AM | 0.92 | 1.92 |
| 2018-06-29 | 1:54 PM | 7/2/2018 | 9:52 AM | 2.83 | 1.83 |
| 2018-07-09 | 11:46 PM | 7/11/2018 | 9:16 AM | 1.40 | 2.40 |
| 2018-06-29 | 11:57 AM | 6/29/2018 | 1:58 PM | 0.08 | 0.08 |
| 2018-07-05 | 1:29 PM | 7/6/2018 | 9:08 AM | 0.82 | 1.82 |
| 2018-07-05 | 3:49 PM | 7/6/2018 | 10:21 AM | 0.77 | 1.77 |
| 2018-06-27 | 10:31 AM | 6/28/2018 | 9:38 AM | 0.96 | 1.96 |
| 2018-07-06 | 2:46 PM | 7/9/2018 | 8:58 AM | 2.76 | 1.76 |
| 2018-06-28 | 3:32 PM | 7/10/2018 | 7:12 AM | 11.65 | 7.65 |
| 2018-06-29 | 3:04 PM | 7/2/2018 | 11:24 AM | 2.85 | 1.85 |
| 2018-07-11 | 10:28 AM | 7/11/2018 | 1:25 PM | 0.12 | 0.12 |
| 2018-07-10 | 3:30 PM | 7/11/2018 | 2:29 PM | 0.96 | 1.96 |
| 2018-06-26 | 4:09 PM | 7/3/2018 | 12:42 PM | 6.86 | 5.86 |
| 2018-06-28 | 9:18 AM | 6/28/2018 | 10:58 AM | 0.07 | 0.07 |
| 2018-07-09 | 11:39 PM | 7/11/2018 | 9:06 AM | 1.39 | 2.39 |
| 2018-07-06 | 10:40 AM | 7/6/2018 | 3:00 PM | 0.18 | 0.18 |
| 2018-07-02 | 9:33 AM | 7/2/2018 | 2:12 PM | 0.19 | 0.19 |
| 2018-07-10 | 12:00 AM | 7/10/2018 | 4:39 PM | 0.69 | 0.69 |
| 2018-07-03 | 8:20 AM | 7/6/2018 | 9:00 AM | 3.03 | 2.03 |
| 2018-06-27 | 8:52 AM | 6/29/2018 | 9:07 AM | 2.01 | 2.01 |
| 2018-07-09 | 12:50 PM | 7/11/2018 | 8:56 AM | 1.84 | 2.84 |
| 2018-07-05 | 2:56 PM | 7/6/2018 | 12:53 PM | 0.91 | 1.91 |
| 2018-07-10 | 8:43 AM | 7/10/2018 | 9:42 AM | 0.04 | 0.04 |
| 2018-07-10 | 8:43 AM | 7/10/2018 | 9:42 AM | 0.04 | 0.04 |
+----------------+---------------+-------------------+------------------+--------+--------+

Too many parentheses:
=NETWORKDAYS([#[ DateTimeStamp]],[#[ DateLastInReview]])-1-MOD([#[ DateTimeStamp]],1)+MOD([#[ DateLastInReview]],1)

The reason could be the way the NETWORKDAYS function works. =NETWORKDAYS("7/12/2018","7/13/2018") evaluates to 2, while 7/13/2018 - 7/12/2018 evaluates to 1.

Related

How to pivot pyspark dataframe rows to columns

I have a simple pyspark dataframe like this:
-------------------------------------------------------
|timestamp_local |timestamp_utc|device|key |value|
-------------------------------------------------------
|2020-11-20 | 2020-11-20 | J3X |Position| SEP |
|2020-11-20 | 2020-11-20 | J3X |Soll | 333 |
|2020-11-20 | 2020-11-20 | J3X |Ist | 444 |
|2020-11-21 | 2020-11-21 | J3X |Position| SOP |
|2020-11-21 | 2020-11-21 | J3X |Soll | 100 |
|2020-11-21 | 2020-11-21 | J3X |Ist | 200 |
-------------------------------------------------------
I want to use pivot function but I am not sure if it's correct.
import pyspark.sql.functions as f
result_df = raw_df.groupBy('timestamp_local', 'timestamp_utc', 'device').pivot('key').agg(f.first('value'))
Desired output:
---------------------------------------------------------------
| timestamp_local|timestamp_utc|device|Position | Soll | Ist
---------------------------------------------------------------
|2020-11-20 | 2020-11-20 | J3X | SEP | 333 | 44
|2020-12-20 | 2020-12-20 | J3X | SOP | 100 | 200
---------------------------------------------------------------
Any suggestions how to do it?

Extract all rows on new sheet where driver name = NS

On a new excel sheet, i am trying to list all rows for a specific drivers name from this sheet.
I want all the rows where the drivers name is NS (or cell A1 on my new sheet). I have over 1000 rows of data and more columns than below but this gives you an idea.
The first line of data is A4:M4
Tried index/match function but unable to get it to work.
+------------+-------------------------------+----------------+-------------+
| Date | Vehicle | Driver | Drops Taken |
+------------+-------------------------------+----------------+-------------+
| 01/04/2019 | LCG - DAF 7.5 Tonner | RL | |
| 01/04/2019 | GXO - Merc 3.5T Dropside | KA | 9 |
| 01/04/2019 | KDZ - DAF 12 Tonner | NS | 12 |
| 01/04/2019 | RYZ - DAF 12 Tonner | MM | 10 |
| 02/04/2019 | GXO - Merc 3.5T Dropside | KA | 8 |
| 02/04/2019 | KDZ - DAF 12 Tonner | NS | 12 |
| 02/04/2019 | LCG - DAF 7.5 Tonner | RL | |
| 02/04/2019 | RYZ - DAF 12 Tonner | MM | 9 |
| 03/04/2019 | KDV - DAF 12 Tonner | NS | |
| 03/04/2019 | GXO - Merc 3.5T Dropside | KA | 8 |
| 03/04/2019 | Hire Vehicle | RL | |
| 03/04/2019 | KDZ - DAF 12 Tonner | NS | 8 |
| 03/04/2019 | RYZ - DAF 12 Tonner | MM | 7 |
+------------+-------------------------------+----------------+-------------+

How do I create condense list in Excel using formula (not VBA)

I am new to this site and haven't done much in Excel of decades (yes, decades), so I forgotten more than I know now.
Background: I am working on a simple pay sheet checking spreadsheet. One Worksheet is input timesheet for data entry, the complex one does all the calculations (Hourly rate; shift loading; tax formula, etc.) and the final worksheet presents the results in the same format as pay slip. Having finished the complex formulas in the calculation sheet, I am now stuck on condensing the results for the final results on the last sheet. I have try numerous functions including: vlookup, index, match, rank.eq, small and others, as per examples of other question on this site. Sample data is:
+----+-----------------------------------------------------+----------------+------------+--------------+--------+--------+-----+--------+
| | A | B | C | D | E | F | G | H |
+----+-----------------------------------------------------+----------------+------------+--------------+--------+--------+-----+--------+
| 1 | Sample data: | | | | | | | |
| 2 | Monday | Ordinary Hours | 30/04/2018 | Day Shift | 10.85 | 21.85 | 1 | 237.07 |
| 3 | Tuesday | Ordinary Hours | 1/05/2018 | | | 21.85 | 1 | |
| 4 | Wednesday | Ordinary Hours | 2/05/2018 | | | 21.85 | 1 | |
| 5 | Thursday | Ordinary Hours | 3/05/2018 | | | 21.85 | 1 | |
| 6 | Friday | Ordinary Hours | 4/05/2018 | | | 21.85 | 1 | |
| 7 | | | | | | | | |
| 8 | | | | | | | | |
| 9 | Monday | Ordinary Hours | 7/05/2018 | | | 21.85 | 1 | |
| 10 | Tuesday | Ordinary Hours | 8/05/2018 | | | 21.85 | 1 | |
| 11 | Wednesday | Ordinary Hours | 9/05/2018 | Day Shift | 10.85 | 21.85 | 1 | 237.07 |
| 12 | Thursday | Ordinary Hours | 10/05/2018 | Day Shift | 10.85 | 21.85 | 1 | 237.07 |
| 13 | Friday | Ordinary Hours | 11/05/2018 | | | 21.85 | 1 | |
| 14 | | | | | | | | |
| 15 | Monday | Overtime 1.5 | 30/04/2018 | | | 21.85 | 1.5 | |
| 16 | Tuesday | Overtime 1.5 | 1/05/2018 | Overtime 1.5 | 2 | 21.85 | 1.5 | 65.55 |
| 17 | Wednesday | Overtime 1.5 | 2/05/2018 | | | 21.85 | 1.5 | |
| 18 | Thursday | Overtime 1.5 | 3/05/2018 | | | 21.85 | 1.5 | |
| 19 | Friday | Overtime 1.5 | 4/05/2018 | | | 21.85 | 1.5 | |
| 20 | Saturday | Overtime 1.5 | 5/05/2018 | | | 21.85 | 1.5 | |
| 21 | | | | | | | | |
| 22 | Monday | Overtime 1.5 | 7/05/2018 | | | 21.85 | 1.5 | |
| 23 | Tuesday | Overtime 1.5 | 8/05/2018 | | | 21.85 | 1.5 | |
| 24 | Wednesday | Overtime 1.5 | 9/05/2018 | | | 21.85 | 1.5 | |
| 25 | Thursday | Overtime 1.5 | 10/05/2018 | | | 21.85 | 1.5 | |
| 26 | Friday | Overtime 1.5 | 11/05/2018 | | | 21.85 | 1.5 | |
| 27 | Saturday | Overtime 1.5 | 12/05/2018 | | | 21.85 | 1.5 | |
| 28 | | | | | | | | |
| 29 | | | | | | | | |
| 30 | Required result on separate sheet in same workbook: | | | | | | | |
| 31 | Taxable Allowances | Comments | Qty | Rate | Factor | Amount | | |
| 32 | Ordinary Hours | 30/04/2018 | 10.85 | 21.85 | 1 | 237.07 | | |
| 33 | Ordinary Hours | 9/05/2018 | 10.85 | 21.85 | 1 | 237.07 | | |
| 34 | Ordinary Hours | 10/05/2018 | 10.85 | 21.85 | 1 | 237.07 | | |
| 35 | Overtime 1.5 | 1/05/2018 | 2 | 21.85 | 1.5 | 65.55 | | |
| 36 | | | | | | | | |
| 37 | | | | | | | | |
| 38 | | | | | | | | |
| 39 | | | | | | | | |
| 40 | | | | | | | | |
+----+-----------------------------------------------------+----------------+------------+--------------+--------+--------+-----+--------+

spotfire- how to find create a column to calculate the time of next stage

I want to create a calculated column to show the time action end grouped by [Case ID], [Stage], and [Action]. The order of the stage is not necessary alphabetic and it could be duplicated. Say after [stage] 'C', we could have another [stage] 'c' in the future
Thanks,
Thanks for the updated test data. The data types are extremely important when asking. Also, the test data should mirror the actual data as close as possible, otherwise solutions often will not scale. For example, in the test data the values are only time. Sorting on time doesn't take into account the day, thus it's all treated equally. Since these values are actually DateTime, I have added that to the test data. These expressions will give you the expected results as identified in your question.
Rank([Time_Action_Begin],"asc",[Case ID]) as [Rank]
Min([Time_Action_Begin]) OVER (Intersect([Case ID],Next([Rank])))
RESULTS
+---------+-------+----------+------------------------+------------------------+------+
| Case ID | Stage | Action | Time_Action_Begin | Time_Action_End | Rank |
+---------+-------+----------+------------------------+------------------------+------+
| 1 | A | approve | 01/01/2016 11:30:00 PM | 01/02/2016 12:30:00 AM | 1 |
| 1 | A | approve | 01/01/2016 11:30:00 PM | 01/02/2016 12:30:00 AM | 1 |
| 1 | B | approve | 01/02/2016 12:30:00 AM | 01/02/2016 1:30:00 AM | 3 |
| 1 | B | approve | 01/02/2016 12:30:00 AM | 01/02/2016 1:30:00 AM | 3 |
| 1 | C | approve | 01/02/2016 1:30:00 AM | 01/02/2016 2:30:00 AM | 5 |
| 1 | C | approve | 01/02/2016 1:30:00 AM | 01/02/2016 2:30:00 AM | 5 |
| 1 | D | approve | 01/02/2016 2:30:00 AM | 01/02/2016 3:30:00 AM | 7 |
| 1 | D | approve | 01/02/2016 2:30:00 AM | 01/02/2016 3:30:00 AM | 7 |
| 1 | E | approve | 01/02/2016 3:30:00 AM | 01/02/2016 4:30:00 AM | 9 |
| 1 | E | approve | 01/02/2016 3:30:00 AM | 01/02/2016 4:30:00 AM | 9 |
| 1 | F | complete | 01/02/2016 4:30:00 AM | 01/02/2016 5:30:00 AM | 11 |
| 1 | F | complete | 01/02/2016 4:30:00 AM | 01/02/2016 5:30:00 AM | 11 |
| 1 | C | approve | 01/02/2016 5:30:00 AM | | 13 |
| 1 | C | approve | 01/02/2016 5:30:00 AM | | 13 |
| 2 | A | approve | 01/01/2016 10:30:00 PM | 01/02/2016 12:30:00 AM | 1 |
| 2 | A | approve | 01/01/2016 10:30:00 PM | 01/02/2016 12:30:00 AM | 1 |
| 2 | B | approve | 01/02/2016 12:30:00 AM | 01/02/2016 2:30:00 AM | 3 |
| 2 | B | approve | 01/02/2016 12:30:00 AM | 01/02/2016 2:30:00 AM | 3 |
| 2 | C | approve | 01/02/2016 2:30:00 AM | 01/02/2016 3:30:00 AM | 5 |
| 2 | C | approve | 01/02/2016 2:30:00 AM | 01/02/2016 3:30:00 AM | 5 |
| 2 | D | approve | 01/02/2016 3:30:00 AM | 01/02/2016 4:30:00 AM | 7 |
| 2 | D | approve | 01/02/2016 3:30:00 AM | 01/02/2016 4:30:00 AM | 7 |
| 2 | E | approve | 01/02/2016 4:30:00 AM | 01/02/2016 5:30:00 AM | 9 |
| 2 | E | approve | 01/02/2016 4:30:00 AM | 01/02/2016 5:30:00 AM | 9 |
| 2 | F | complete | 01/02/2016 5:30:00 AM | 01/02/2016 6:30:00 AM | 11 |
| 2 | F | complete | 01/02/2016 5:30:00 AM | 01/02/2016 6:30:00 AM | 11 |
| 2 | C | approve | 01/02/2016 6:30:00 AM | | 13 |
| 2 | C | approve | 01/02/2016 6:30:00 AM | | 13 |
+---------+-------+----------+------------------------+------------------------+------+

Calculating median with three conditions to aggregate a large amount of data

Looking for some help here at aggregating more than 60,000 data points (a fish telemetry study). I need to calculate the median of acceleration values by individual fish, date, and hour. For example, I want to calculate the median for a fish moving from 2:00-2:59PM on June 1.
+--------+----------+-------+-------+------+-------+------+-------+-----------+-------------+
| Date | Time | Month | Diel | ID | Accel | TL | Temp | TempGroup | Behav_group |
+--------+----------+-------+-------+------+-------+------+-------+-----------+-------------+
| 6/1/10 | 01:25:00 | 6 | night | 2084 | 0.94 | 67.5 | 22.81 | High | Non-angled |
| 6/1/10 | 01:36:00 | 6 | night | 2084 | 0.75 | 67.5 | 22.81 | High | Non-angled |
| 6/1/10 | 02:06:00 | 6 | night | 2084 | 0.75 | 67.5 | 22.65 | High | Non-angled |
| 6/1/10 | 02:09:00 | 6 | night | 2084 | 0.57 | 67.5 | 22.65 | High | Non-angled |
| 6/1/10 | 03:36:00 | 6 | night | 2084 | 0.75 | 67.5 | 22.59 | High | Non-angled |
| 6/1/10 | 03:43:00 | 6 | night | 2084 | 0.57 | 67.5 | 22.59 | High | Non-angled |
| 6/1/10 | 03:49:00 | 6 | night | 2084 | 0.57 | 67.5 | 22.59 | High | Non-angled |
| 6/1/10 | 03:51:00 | 6 | night | 2084 | 0.57 | 67.5 | 22.59 | High | Non-angled |
+--------+----------+-------+-------+------+-------+------+-------+-----------+-------------+
I suggest adding a column (say hr) to your data (containing something like =HOUR(B2) copied down to suit) and pivoting your data with ID, Date, hr and Time for ROWS and Sum of Accel for VALUES. Then copy the pivot table (in Tabular format, without Grand Totals) and Paste Special, Values. On the copy, apply Subtotal At each change in: hr, Use function: Average, Add subtotal to: Sum of Accel then select the Sum of Accel column and replace SUBTOTAL(1, with MEDIAN(. Change Average to Median if required.

Resources