Finding MTD, QTD, and YTD in excel from monthly returns - excel

I've been working on this for awhile and can't seem to find an appropriate way to code this.
Goal: Take a list of monthly returns that currently spans over three years (this is an automated list so it will keep adding months) and find MTD, QTD, & YTD using function so I can automate the process.
Problem: I've tried the OFFSET function, different versions of COUNT, IF statements and can't find a way to properly code the function.
NOTE: this is for stock data/earnings report
Just to clarify, I know how to do this manually, but want to automate the process :) Would be more than happy to use VBA but would like to stick to a simple function if possible...
I'd be more than happy to email the WS to someone. Thanks so much!!

If you want to keep it simple and avoid vba here is a suggestion
The manner in which the data sheet is presented matters.
I assume months go down, with there only being 1 column for 'monthly returns'?
On a separate area/worksheet, set up the months with a value for what they are in the column next to them. Ie
Jan 1
Feb 2
Mar 3
Apr 4
...
Dec 12
then have a drop down where you can select what month it is.
so if it is Jul, you can select Jul.
From here, do a vlookup/indexmatch to pull the number for the month through, so Jul would be 7
From here the MTD is easy.
Do an offset from the beginning of the year to the current month
=offset ([start point],[month number],[columns])
=OFFSET($D$1,$C$21,0)
start point will be one row above Jan, that way when Jan is chosen it will fall onto Jan.
Month number you will get from what was said earlier
and columns will depend on how you place it
YTD, you will do the same as above but have a sum
so
=sum(B3:offset ([start point],[month number],[columns]))
=SUM(D2:OFFSET($D$1,C21,0))
QTD would be easiest just plotting the sums as it would never change
So set out Q1,Q2,Q3 and Q4 as prefixed ones. Then lookup to them.
However, if you want to see the most recent quarter by a formula. On the month number list add a new column which says what quarter it is. Then
Jan 1 1
Feb 2 1
Mar 3 1
Apr 4 2
...
Dec 12 4
It should the read off a formula like so
=SUM(
OFFSET([start point],(INDEX([month number table],MATCH([month],[month list],0),3)-1)*3,0):
OFFSET([start point],INDEX(month number table],MATCH([month],[month list],0),2),0))
=SUM(
OFFSET($D$2,(INDEX($F$2:$H$13,MATCH($C$20,$F$2:$F$13,0),3)-1)*3,0):
OFFSET($D$1,INDEX($F$2:$H$13,MATCH($C$20,$F$2:$F$13,0),2),0)
)
What you are doing is to find the month at the beginning of the quarter and then sum to the current month.
Regarding this bit at the end
OFFSET([start point],(INDEX([month number table],MATCH([month],[month list],0),3)-1)*3,0):
You are finding the month quarter index number(1,2,3,4) and multiplying it by three. The reason you want to take away one before multiplying by three is because you want the start point of the quarter, thus in jan to march, this will be 0, and then you add a row to get the start point being Jan.
In Oct to Dec this will be (4-1) = 3. 3x3 = 9 which will be Oct to make Oct being the start point. Amend as need be.
The yellow section is what your actual information is presented as
The green section is your lookup area
The Blue area is information you are looking for with the lower bit reading from the lookup

Related

Make values zero for specific days in a week and add them evenly across other days for same week

I have this sample dataset. I am trying to figure out a formula in Excel to make the values for Saturday and Sunday zero for each week then take the sum of these two days and add it evenly across the remaining five days of the same week.
For e.g. in the table in image attached below for week 19, Sun = 1 and Sat = 7. In the output, I want the values for Sun and Sat to be changed to zero but the sum Sun = 1 and Sat=7 which is 8 needs to be divided equally among the remaining five days 8/5 = 1.6 and then added to the remaining days for the same week. I need to do this for every week.
Output Sample
I have tried using a formula like this but not sure what to do next:
=IF(OR(B3="Sat",B3="Sun"),0,D3+((VLOOKUP(CONCAT(C3,B3),$E$2:$G$15,2,FALSE))/2))
First test if Sun or Sat. Then use SUMIFS to return the value for those two days and divide by 5 and add it to the value:
=IF(OR(A2={"Sun","Sat"}),0,SUMPRODUCT(SUMIFS(C:C,B:B,B2,A:A,{"Sun","Sat"}))/5+C2)
Or if one has Office 365 and wants a spillable formula:
=LET(
dy,A2:A15,
wk,B2:B15,
sl,C2:C15,
wkend,(dy="Sun")+(dy="Sat"),
IF(wkend,0,SUMPRODUCT(SUMIFS(C:C,B:B,wk,A:A,{"Sun";"Sat"}))/5+sl)
)

Duplicate in Excel

I am having an issue with excel formula which I am unable to write. I have 2 columns Interest rate and Maturity. Through pivot I get the data year wise. Problem is that when there are multiple values for same year, pivot should keep value as blank and I also need to add a formula that checks if interest rate for particular year remains same like in below case of 2021. If that stands true then I need to populate value. If you provide me a code for VBA or formula then it will be a big help !!!
Int Rate Maturity
2.14% 2020
4.08% 2023
3.82% 2024
3.19% 2026
3.93% 2027
2.11% 2021
2.11% 2021
2.79% 2019
2.99% 2023
This is how I solved it:
Start with a simple COUNTIF to count whether a year is duplicate or not.
Then create a (hidden) column that concatenates the year and its interest rate by using CONCAT.
Now perform the same COUNTIF on the column containing the concatenated data. By testing this column, you are testing the uniqueness of a combination "year-interest rate".
Use a simple IF. If the number you obtained in (1) is equal to the number obtained in (3) it means the year/interest rate combination is valid. If the numbers are not equal, it means there are at least 2 conflicting entries.

How to: Aligning data on different time intervals in Excel

I'm looking to compare data that is from different time interval. I'm an Economics student and I'm trying to compare data that is released monthly and data that is released yearly. Specifically how the number of jobs created in a given month influences the GDP figure.
I'm neither allowed to post images or enough links with my current reputation so here's my beautiful collage to illustrate what I'm asking:
http://s22.postimg.org/jpspa1pvl/Screenshots.jpg
The frequency is different. The NFP (Jobs created) are released monthly, GDP is released yearly.
I'm wanting the GDP numbers to go at the start of the corresponding year. This is where I was having problems with VLOOKUP. I could't get it to align correctly or not repeat itself.
An illustration of the graph I'm after.
EDIT: To make it clearer
http://s15.postimg.org/qcg70u5aj/Screenshots1.jpg [ignore the graph]
Here's what I'm looking for without the dodgy formatting. So the first screenshot is the data. And the second is what I'm looking for.
The GDP data is released on the September each year, but it details the entire year of GDP growth. So I want compare it with the Job Figures (that are released monthly). So there will be 12 Job Figures (NFP) to each GDP figure.
Thanks.
PS: Sorry if there's similar questions. I don't know what keywords to search to get the answer.
I set up a sample worksheet as follows:
Column A, from Row 5 to 57 has dates: firsts of consecutive months 1/1/80, 2/1/80 etc
Column B, from Row 5 to 57 has random numbers for Non-Farm Payroll
Column D, from Row 5 to 17 has dates: Sep 30 of consecutive years 9/30/80, 9/30/81 etc
Column E, from Row 5 to 17 has random numbers for Annual GDP
Then I did this:
Column C, from Row 5 to 57: I added the formula =IF(AND(DAY(A5)=1,MONTH(A5)=1),VLOOKUP(DATE(YEAR(A5),9,30),$D$5:$E$17,2,FALSE),"")
Explanation
If the date in column A is the first of Jan (of any year), look up the 30th of Sep of same year in the GDP table and pick up the corresponding GDP value from the second column of that table ($D$5:$E$17). If not, leave the cell empty
Note
Once you have this modified to suit your purpose, you might want to copy those cells in Column C and do a paste-special (Alt-E, S) of them right back in the same place, pasting only the values so that the formulae are gone and you're not tied down to the GDP table.

Formula to determine how many days have passed using year and Julian date

I have a form I built in Excel that uses the MID formula to deconstruct an eight digit numeric code (like 15317087) into three parts, and produces a corresponding output for each piece. The first part 15 is the year. The second part is the Julian day 317 and the last part 087 represents a county number the code was mailed in from.
Here's how it looks:
Notice how 15 isn't used. This is because on another page I have a number representing the total number of days passed between 2015 and... well whatever the initial "0 date" is in Excel. As it would happen, that number for 2015 is 42002. To produce the Gregorian date, I use:
INT(SUM(MID(A2,3,3), 'Date Conversion'!A$1))
which just adds that number to the Julian date.
The problem is next year I will have to change the Date Conversion'!A$1 value from 42002 to 42002 + 365 manually, because not every year has the same number of days. Is there some mathematical way to account for this, or must I update the field manually?
If you're willing to run into a y3k problem, you could convert the '15' into a year as follows:
=DATE(2000+VALUE(LEFT(A2,2)),1,1)
This give you Jan 1 of whatever year is in the left 2 numbers, resetting to the year 2000 during calendar year 3000. Presumably changing the formula at that time will not be burdensome.
So, the Julian calendar used by Excel shows Jan 1 2015 (per my above formula) as 42005 [number of days since Jan 1 1900]. This can then be inserted into your conversion to Gregorian.

merging the cells with the same value as one

I have data which gives me the months and their respective weeks splitted.
I want to merge the cells as one for their respective months.
for example
my data is like this
july july july july july aug aug
1-7 8-14 15-21 22-28 29-3 4-10 11-17......
it should display as
july aug
1-7 8-14 15-21 22-28 29-3 4-10 11-17.....
both my month and weeks are generated dynamically, so, i cant say the exact position.
how i can calculate the position and merge the cells get it in macros in excel?
Somewhere on SE someone described merged cells (I think quite accurately) along the lines of “a creation of the Devil to try us beyond endurance”. Where used they could often be avoided by using Center Across Selection. In you case however I would suggest not bothering to find the position but merely blanking repeats after finding the first instance (therefore regardless of which month that is) which hopefully would make the code much simpler.

Resources