Select a "tax month" with a non standard month start/end - google-sheets

I have a Google Sheet with data like this:
Date
In
Out
July 13
£40
July 21
£60
etc.
I'd like to add another column "month" which specifies what month the entry was made in. Only problem is I can't use the standard MONTH() function because for accounting purposes, the tax month is 16th - 15th. So July 13 would be considered to be in the June/July tax month, while July 21 would be considered to be in the July/August tax month.
I'm assuming I will need to maintain a table of the specific cut off dates like so:
Month
Start
End
Jun/July
16th June
15th July
etc.
But I can't work out how to use this as a lookup table to achieve what I want. Any thoughts appreciated.

I think this should work if your date is in A1:
=IF(DAY(A1)>15,TEXT(A1,"MMMM")&"/"&TEXT(A1+20,"MMMM"),TEXT(A1-20,"MMMM")&"/"&TEXT(A1,"MMMM"))
If sort order is important (e.g. in a subsequent pivot table) I would use this:
=IF(DAY(A1)>15,TEXT(A1,"MM MMMM")&"/"&TEXT(A1+20,"MMMM"),TEXT(A1-20,"MM MMMM")&"/"&TEXT(A1,"MMMM"))
Another way to specify the sort order is maintaining a separate table with sort order column. It's a completely different approach.

use:
=ARRAYFORMULA(IF(A2:A="",,IF(DAY(A2:A)<16,
TEXT("1/"&MONTH(A2:A)-1, "mmmm")&"/"&TEXT("1/"&MONTH(A2:A), "mmmm"),
TEXT("1/"&MONTH(A2:A), "mmmm")&"/"&TEXT("1/"&MONTH(A2:A)+1, "mmmm"))))

Related

How to get last closing price of a stock in google finance (In a non-trading day)

I tried using
=INDEX(GOOGLEFINANCE("NASDAQ:MSFT","price",TODAY(), 2),2,2)
And saw that on some days (e.g. 12/6/2021, a Saturday) the function failed to return value. I assume that it is because there was no trading on that day.
Is there a way for me to pick the last value of a stock prior to that day? (e.g. If I calculate on a Saturday or on a Sunday with an American stock I would get Friday's value, Thursday for an Israeli stock etc.)
I am not aware of a way for GOOGLEFINANCE to automatically adjust for no trading days.
One way to do it is to get the "price" data for the last 7 days (to be safe) and then query that data to get the "price" value next to the max date.
This formula works for me:
=INDEX(QUERY(GOOGLEFINANCE("NASDAQ:MSFT","price", TODAY()-7, TODAY()),"select Col1, Col2 order by Col2 desc",1), 2, 2)
You can use the formula below, in the cell that you want the price to be.
=INDEX(GOOGLEFINANCE(A5;"price";$B$2);2;2)
Where A5 contains the stock symbol, like CMI, JNJ, NEE or whatever.
And the B2 contains the following formula:
=if(weekday(B1)=2;B1-3;if(weekday(B1)=1;B1-2;B1-1))
Finally, B1 is just =today().
This will adjust the day for weekdays only. So if it is Saturday, Sunday or Monday, it will give you the price of the stock on Friday.
Basically it will give the last closing price on business days.
Best regards.

How to Calculate Age from Year Only in Google Sheets

I have the year a car was purchased in column A. For example, 2015. I'm trying to calculate the age of the vehicle comparing the year provided in column A to TODAY() in an arrayformula, like this...
={"Vehicle Age";arrayformula(if(A2:A="",,(datedif(A2:A,today(),"Y"))))}
For some reason, it gives me the number 115 as the result for every cell where a year has been specified. Any idea why? I can't seem to find an answer on this anywhere on the internets.
Thanks for your help!
You are mixing apples and oranges here, so to speak.
Internally, Google Sheets sees all full dates as a number of days from an origin point of December 31, 1899. As such, the year 2015 on its own, in a comparison with a full date will be seen as two-thousand-fifteen days since December 31, 1899 (or July 7, 1905 — which was 115 some-odd years ago, as would be the case with any relatively recent year, because they'll all be interpreted in their raw form by Sheets as a cluster of days from late June to early July of 1905).
Instead, you want to compare the years only, which will mean extracting the year from TODAY(), since A2:A are already year-only numbers:
={"Vehicle Age";arrayformula(if(A2:A="",,year(TODAY())-A2:A))}
However, since any year's car models are actually released the year before, you may want to add a year to your formula:
={"Vehicle Age";arrayformula(if(A2:A="",,year((TODAY())-A2:A)+1))}
Of course, you could also have turned your A2:A years into real dates (e.g., January 1 of each year listed) and then used datedif as well:
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")))}
... or with that extra year added ...
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")+1))}
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")))}
Not working

Commission calculation based on sliding month (googlesheets)

I have to pay a commission to Agents (affiliates) based on the following conditions:
the commission starts on a monthly basis following a USER (linked to the Agent) first deposit/purchase on a website
agents have a decreasing commission, ex: 1 month following first deposit of their USER = 30% of sales, 2d month period following 1st deposit of USER: 25% of sales, etc
Commission are paid on a month basis calculation (ex: from 01/07/2020 till 31/07/2020)
If a USER makes a first purchase on June 22d and if sales commission for 1st period is 30%, then agent is eligible to a 30% commission on sales from june 22d till July 22d, then 25% for sales from 23rd july till 23rd august, etc
I have designed a googlesheets (see below) that serves the purpose (using 12 columns to get the correct commission% for a specific user on a specific day!), but I am trying to find a more straight forward formula to get the applicable com. % based on the commission sliding table and the first deposit date of a specific user.
Can anyone help?
The google sheets showing my calc is here:
https://docs.google.com/spreadsheets/d/1I1gzZ670hJH8HwCGizzbvlQkg0dgAvgOSQTfOUL0VgU/edit?usp=sharing
This might help you. (Updated to correct the row number of where the formula should go.)
If you insert a new column in your sheet, to the right of Column W, the Current Commision Month, and paste the following formula in the cell where the Current Commision Month header text should appear (Row 9 in your sample) of that column, it replicates the results in your Current Commision Month.
But it does not require columns I through V. You can test that by deleting columns I through V - you can use Undo and Redo to go back and forth, if necessary. Depending on how you use your "End" column - the logic wasn't clear to me - the info for that can also be gained in this one column.
={"Current
Commision
Month";"";ArrayFormula(
if(
($H11:H<>"") * ($A11:A>=date(year(H11:H),month(H11:H),day(H11:H))),
ifs( $A11:A< date(year(H11:H),month(H11:H)+1,day(H11:H)),1,
$A11:A< date(year(H11:H),month(H11:H)+2,day(H11:H)),2,
$A11:A< date(year(H11:H),month(H11:H)+3,day(H11:H)),3,
$A11:A< date(year(H11:H),month(H11:H)+4,day(H11:H)),4,
$A11:A< date(year(H11:H),month(H11:H)+5,day(H11:H)),5,
$A11:A< date(year(H11:H),month(H11:H)+6,day(H11:H)),6,
$A11:A>=date(year(H11:H),month(H11:H)+7,day(H11:H)),9999),
""))}
The first IF test is to check that the FirstDeposit date is not blank, and that the sale date is greater than or equal to the FirstDeposit date.
The IFS tests go through and check whether the sale date is less than one of the months, and stops at the first value (commission month) that is greater than the sale date. If never, it places a vlaue of 9999.
Note that the "9999" values are just to indicate the sale date is greater than the "End" date, and can be changed to blanks or whatever you want.
[![enter image description here][1]][1]
I've added a sample tab with the final result. Let me know if this helps. There may be several other enhancements possible for your sheet, in particular the use of ARRAYFORMULAS to fill values down many of your columns.
I haven't spent time on the actual commision calculations, in the final columns, but if you feel that still needs improvements, I can try to simplify there as well.
[1]: https://i.stack.imgur.com/TfFZ5.png

Google Sheets, increment cell by month

I have a spreadsheet that keeps track of how old accounts are by months.
Is there a way to have Google Sheets auto update a cell on the 1st of each month?
VG: An account is 78 months old and on Sept 1st it turns 79 months. I want to automatically update it on the 1st of the month so I won't have to manually add 1 to every account age cell.
This is for Excel:
If the value is 78 on 25 August 2016 and you want the value to increment of the first of each month, then enter:
=78+MONTH(TODAY())-MONTH(DATEVALUE("8/25/2016"))+12*(YEAR(TODAY())-YEAR(DATEVALUE("8/25/2016")))
Assuming that your dataset does include an account start date in column A, you can calculate how many whole months are between that date and system date today by using:
=DATEDIF(A2,TODAY(),"M")
Tested this in Excel but should work in Google Sheets as well.
You could add another field, and do the calculation from the sheet:
[A1]=<start date>
[A2]=datedif(a1,today(),"M")
Otherwise, you could use a script to do this once a month, but you would need a list of cells somewhere that need to be updated. I would need to see an example of your spreadsheet layout to give you working code.
The process would be to:
set a daily trigger
check for the first of the month
if it is, go and update all the cells
if not, try again tomorrow
This worked out well for me in Google Sheets
DATEDIF("<MY_STARTING_DATE>", today(), "M")
example:
DATEDIF("8/1/2021", today(), "M")

Roll-Forward Date Patterns in Excel

Using Excel 2010, I need to take an existing date in 2015 (i.e. 2/11/15), and calculate the same date position in the next year. In other words, whatever is the specific date pattern with the existing date, I'm looking for a formula that will help me calculate the exact same date pattern. If 2/11/15 is the second Wednesday in February of 2015, I need a formula to help me calculate (using the existing date) the second Wednesday of February in 2016.
#Jeeped, thanks for your reply. You're correct - there's many "conditions" to account for. Two colleagues helped-out with the following:
=IF('Data (Reference)'!C14>"", CONCATENATE(TEXT('Data (Reference)'!C14, "MM"),"/", TEXT(7-(WEEKDAY(CONCATENATE(TEXT('Data (Reference)'!C14,"MM"),"/", Input!$C$2))-1)-7+TEXT(WEEKDAY('Data (Reference)'!C14), "DD")+(CEILING(TEXT('Data (Reference)'!C14, "DD")/7, 1)-(IF(TEXT(WEEKDAY('Data (Reference)'!C14), "DD")
We had to consider wherever the existing date fell, and dynamically identify the pattern and/or condition and re-apply it in the roll-forward sequence.

Resources