Formula To Calculate Accrued Quarterly Allowance Based On Employment Length - google-sheets

Employees get a specified amount of allowance for each quarter of the year, which accrues as the year progresses, and resets each new year. The amount they get each quarter is determined by how long they have been employed.
YEARS EMPLOYED | $ PER QUARTER
<1 | $0
>=1 | $37.5
>=3 | $66.66
>=5 | $100
Using only one reference cell (the hire date in Cell O1), I'm trying to figure out how to put a formula together which would display the sum of all quarterly amounts accrued this year to date.
The part that is giving me trouble is that when the amount per quarter changes during the year (due to the number of years employed reaching the next level), any previous quarters for the year need to remain at their previously assigned amounts, for example:
If the HIRE DATE is April 16, 2015:
QUARTER | YEARS HIRED | QUARTERLY ALLOWANCE
Q1 | 2.71 | $37.5
Q2 | 2.96 | $37.5
Q3 | 3.21 | $66.66
Q4 | 3.46 | $66.66
If TODAY'S DATE is May 21, 2018, the total allowance amount to date = $75 (Q1+Q2)
If TODAY'S DATE is Oct 7, 2018, the total allowance amount to date = $208.32 (Q1+Q2+Q3+Q4)
How can this be done with one formula, using only the hire date in Cell O1?

I think the easiest way to get the number of complete years hired is to use Datedif:
=DATEDIF(O$1,DATE(YEAR(P$1),RIGHT(A2)*3-2,1),"Y")
placed in (say) E2, where the current date is in P1 and the list of quarters starts in A2
Then a lookup to get the allowance calculated on the first day of each quarter:
=LOOKUP(E2,{0,1,3,5},{0,37.5,66.66,100})
and finally a check to see if the first day of the quarter is on or before the current date:
=P1>=DATE(YEAR(P1),MONTH(RIGHT(A2)*3-2),1)
Then you could get the total from
=SUMPRODUCT(F2:F5*G2:G5)
Or you could combine all this into one big array-type formula:
=SUMPRODUCT((P1>=DATE(YEAR(P1),{1,4,7,10},1))*LOOKUP(DATEDIF(O1,DATE(YEAR(P1),{1,4,7,10},1),"Y"),{0,1,3,5},{0,37.5,66.66,100}))

Related

Check if a date in an index matches the date of a cell

I have this spreadsheet which is a Cash Flow and the payments vary from monthly, quarterly, every 6 months and so on. When it comes to payments every x months, I'm having trouble creating a formula to check if the amount should be added to x month, for example:
I have columns with each month of the year:
01-2021 | 02-2021 | 03-2021 | 04-2021 | 05-2021 | 06-2021...
Then I made a separate table to calc when the amounts should be added, which equals to the start month and year, then that day + 6 months (in the case of payments every 6 months) and so on:
Start date: 01-2021
Value: $100
First payment: 01-2021
Second payment: 07-2021
Third payment: 01-2022
...
And the amounts of this specific case should be added under the respective months ($100 under 01-2021, another $100 under 07-2021, another $100 under 01-2022...)
I've made a INDEX(MATCH)) that returns all the payment dates based on the "start date", but how can I check they match the dates of the first table mentioned?
IF(date_from_table = any of the dates in the array, amount, 0)
Thanks in advance!
use:
VLOOKUP(date_from_table, dates in the array and amount, amount, exact match)
=INDEX(IFNA(VLOOKUP(A2:A, Sheet1!A:B, 2, 0)))

Google Sheets duration between 2 timestamps where the ending timestamp crosses into midnight

I have a sheet where I'm calculating the durations of time between two timestamps.
As an example, I have column A, which is the starting time, and column B, which is the stopping time. Both A and B are formatted as Time. Column C holds the duration between A and B, and is formatted as Duration.
The formula =SUM(B1 - A1) works fine for the most part, until I reach a situation in which B1 has crossed into midnight of the next day
For example if I have the following:
A | B | C
------------------------------
23:30 | 23:40 | 0:10:00
23:30 | 23:50 | 0:20:00
23:30 | 00:00 | -23:30:00
23:30 | 00:10 | -23:20:00
How do I circumvent this issue and have C3 & C4 properly calculate the value to be 0:30:00 and 0:40:00 respectively? My timestamps don't include date-related information, columns A and B only hold HH:MM:SS times. These durations will also never be longer than a maximum of 3 hours, so there's no need to worry about it correctly detecting overflow situations like Day 1 12:00:00 -> Day 2: 12:00:00 = 24:00:00
For mixed duration that crossed midnight of the next day (overlaps midnight)
try either of the following formulas.
=ArrayFormula(IF(A42:A="",,MOD(B42:B-A42:A, 1)))
OR
=ArrayFormula(IF(LEN(A42:A)<>0,
IF(B42:B55<A42:A,B42:B-A42:A+1,B42:B-A42:A),""))
Please adjust ranges to your needs
If you format the result column as Time, you don't need to change anything. If not, here is another option:
=B2-A2+(B2<A2)
Edit
An attempt with an array formulas:
First two results formatted as Time, last as Duration

Time differance "in mins" using current date and time stamp

How do I work out the duration from the current date and time to cell A1
A B Results
+-----------------+-------------------------------------------------------+--------------+
1 |20-01-07 07:27:27|=TIME(HOUR(NOW()),MINUTE(NOW()),SECOND(NOW()))-C2 | 5:31:57 |
+-----------------+-------------------------------------------------------+--------------+
2 |20-01-07 07:27:27|=TIME(HOUR(NOW()),MINUTE(NOW()),SECOND(NOW()))-C2*1440 | -56307326.9 |
+-----------------+-------------------------------------------------------+--------------+
I have tried this method above but it seems to not use the DATE.
Is there a way I can get it to include the date and also get it to display in minutes
https://docs.google.com/spreadsheets/d/15EqEkdzcPntTV1K0EfOW_BPcq7zFDNqOMNwEFdQuDIE/edit#gid=0
use:
=ARRAYFORMULA(IF(A2:A, TEXT(NOW()-A2:A, "[m]")*1, ))
=now() - A1 will give you the number of days between the date in A1 and now.
The decimal part of the number if a fraction of a day.
So if you need minutes, try the formula :
=(now()-A1)*(24*60)
The output will most likely have decimal places which is the number of seconds as fractional minutes.

Total hours of overtime

I keep a google spreadsheet where I enter hours worked per day. I'm supposed to work 8 hours per day and anything more than that is overtime.
So I need to check if a value in the column with hours is greater than 8. If so I want the difference between 8 and the value entered, added to or accumulated in another cell so that I can see how many hours of overtime I have worked. Also if the value is less than 8 then I need to make a deduction.
Can anyone help me with such a formula?
Let's say your hours are entered in column B, and start on row 2. In a column further along, put the following formula:
=if(B2>8,B2-8,0)
This first checks whether that day have any overtime =if(B2>8 - if it does, it calculates how much B2-8 - if it doesn't, it shows 0 instead.
Then, underneath that column, you can sum for your answer. It will look something like this.
A | B | C
Day | Hours | Overtime
------------------------------
Monday | 8 | =if(B2>8,B2-8,0)
Tuesday | 9 | =if(B3>8,B3-8,0)
Wednesday | 9 | =if(B4>8,B4-8,0)
Thursday | 8 | =if(B5>8,B5-8,0)
Friday | 10 | =if(B6>8,B6-8,0)
------------------------------
Total | Total | =SUM(C2:C6)

Calculate working time subtracting lunch time if needed

I'm struggled with a spreadsheet that contains how much time I have been working. I have in each row the start time and end time of each working day.
Example sheet:
| | A | B | C |
----------------------------------------------
|1 |Start time |End time|Total time |
|2 |7:00 |13:30 |6:00 |
|3 |7:00 |10:00 |3:00 |
Shared table
The issue is that the total time should not consider lunch time. I want to set up a sheet that will automatically take out the half hour for lunch when the total time is greater than 4 hours. For example, if the start time is 7:00 and the end time is 13:30, I want to get 13:30-7:00 that is 6:30 minus 0:30=6:00. However, if the start time is 7:00 and the end time is 10:00, I want to get 10:00-7:00, that is 3:00. I tried =SUM(-(A2-B2)*24) but without success.
The expected output is in red. I want to obtain such output using formulas.
Thank you!!!!
Formula to be dragged down:
=mod(B2-A2;1)-if(mod(B2-A2;1)>time(4;0;0); time(0;30;0); 0)
Because of the mod() function this formula should deal with 'negative' hours in case of overnight time.
Or in arrayformula:
=ArrayFormula(if(len(B2:B); mod(B2:B-A2:A;1) - if(mod(B2:B-A2:A;1)>time(4;0;0); time(0;30;0); 0);))
Format the output column as 'duration'...

Resources