excel formula for previous quarters - excel-formula

I am looking for a formula to pull up the previous quarter and year like in the Column J, for the Oct 20, it should return Q3 20 instead of Q4 20.
Currently my formula only returns the correct quarter but I would need the previous to last quarter and year?

To return the quarter | year corresponding to 3 months ago, i.e. :
"previous quarter & year"
simply replace col H date references with edate(date,-3). Cell J17 formula to enter is then:
="Q"&ROUNDUP(MONTH(EDATE(H17,-3))/3,0)&" "&YEAR(EDATE(H17,-3))
If you have Office 365 compatible version of Excel, you could shorten (albeit ever so slightly in this case) with the let function as so:
=LET(x,EDATE(H17,-3),"Q"&ROUNDUP(MONTH(x)/3,0)&" "&YEAR(x))

Related

In Excel how to count between date1 and date2 that have cells in row that contain text?

I need to choose cells in one column that are between two dates, and then based on the rows that contain those dates, choose cells in another row that also contains content.
I didn't use ISBLANK because it counts a formula yet an empty cell as a not-blank. Instead check if there is content by "*".
Here is what I came up with, but instead of returning the number of cells, instead this returns TRUE (which obviously isn't what I want).
In the formula below I am assuming:
C:C is the whole column containing DATES.
E:E is the whole column containing CONTENT.
The date range in this case is January 1, 2018 to January 31, 2018.
"*" means is there is content in the cell
=IF(AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*"))=0,"",AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*")))
My goal is to:
count the numbers of the cells in column E that are between the dates in column C
if the whole formula is 0, then return a blank.
See this picture of a sample excel sheet to make my intent clear:
How can I get my formula working so it does as needed?
SOLUTION
Hi all, so thanks to #girlvsdata, we have a working solution. I had to do a couple edits to her code to work for my uses, but her formula overall works perfect. Here is the solution:
To choose all cells in column E that are not blank, in between the date range of all of January (unknown end date) based on the adjacent C column if that is your date column, then the solution is:
=IF(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*")=0,"",COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*"))
Note that "2018-1-1" is January 1 2018, and EOMONTH("2018-1-1",0) is the last valid day of January in the year 2018 (in this case, 31, but if it is different another year (e.g. for February this works for leap years too) then it will be that last day). Also it eliminates the need to calculate which is the last day or every month, as well as months that have changing end dates dependent on the year (e.g. Feb). This is important to eliminate a margin of error.
The only thing you have to do to change the month is only change e.g. -1- (Jan) to -2- for Feb, or change the year for other years. With this formula you can ignore the day part.
If the answer is 0 (no cells have any content in between the range), then the cell is blank instead of 0. (GOod for when you want to create a sheet checking future dates for future reference when more rows are added to the sheet.
It also works across different sheets, just use, say your other sheet is called "Tracker" then use Tracker!C:C and Tracker!E:E. Hope it helps!
Thank you all! :D
(Please note: My local date format is day, then month)
With the data laid out as in your example above:
A B
1 Dates |Content
------------+-------
2 1/01/2018 |
3 2/01/2018 |123456
4 3/01/2018 |
5 4/01/2018 |12398
6 5/01/2018 |484
7 6/01/2018 |1538
8 7/01/2018 |
9 8/01/2018 |
10 9/01/2018 |
11 10/01/2018 |14648
12 11/01/2018 |
13 12/01/2018 |145615
14 13/01/2018 |
And with the date range in cells D2 and E2:
Date Start Date End
2/01/2018 7/01/2018
This formula returns the count:
=COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")
This will depend on whether your numbers in Column B are formatted as text or number. If they are formatted as numbers, the above formula will work. If they are formatted as text, replace the last section ">0" with "*".
This formula adds the conditional part of your question:
=IF(COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")=0,"",COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0"))
(If the formula returns 0, show blank)

Automatically change excel cell value depending on current Month

Stock analysis Dashboard. I need to compare the stock from today vs the previous 6 months.
My stock data
Cell A1:R1 - month data example Cell A1= June 2017, B1= 7/2017 ....till R1= December 2018.
Cell A2:R2 Stock numbers data example A2=23, B2=25,........till R2=50.
IF I want to see the stock today month which is July 2018= M1 vs six months February 2018 H2 and the stock level calculation will which is M2=26 - H2= 30 =-4.
But instead of entering formula every time I need to be updated every month based on the today month?
Any tips on how to do it?
Thanks
I also miss a date...
If you use today() function to identify today's date you can use:
=HLOOKUP(TODAY(),$A$1:$S$2,2)-HLOOKUP(DATE(YEAR(TODAY()),MONTH(TODAY())-5,1),$A$1:$S$2,2)
If you need a cell with a specific date, replace today() formula with that cell.
I find the question a bit confusing. If A1 is June 2017, I am missing a month if R1 is December 2018 and July 2017 is in M1. Also, even though you said 6 months, I am assuming that you want 5 months so that July compares to February.
This response assumes that A1 is wrong but R1 and M1 (and B1 through R1 are accurate) and that the values in A1 through R1 are actually an Excel date that is formatted as m/yyyy (as opposed to some text representation of a date).
This formula is further complicated since I do not know what day is used in the date representation in A1 through R1, hence I am adapting both that date and the current date to be a fixed day of the month (I chose the first day of the month in my formula).
Here is the formula that computes the -4 assuming M1 is 7/2018, M2 is 26, H1 is 2/2018, H2 is 30 and we want to compare column M to column H since today is in July and we want to compare July to February (5 months difference):
=INDIRECT("R2C"&MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0),FALSE)-INDIRECT("R2C"&MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0)-5,FALSE)
This is an array function so it needs to be entered with [Ctrl]+[Shift]+[Enter].
The way it works is that it computes from today's date, the date value equal to the first day of this month. Then it compares that against the range A1:R1 with each of those dates likewise moved to the first of the month. This gives us the column to use for "this month" and using the same computation but subtracting 5 gives us the column to use for "six months ago." Out of sheer laziness I used these values in an indirect cell reference to pull the Row 2 values for "this month" and "six months ago" and subtracted the latter from the former (i.e., "this month" - "six months ago").
In other words, this part of the formula gives me the column of the current month:
MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0)
and this part gives me the column of the month six months ago (as defined in the original post):
MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0)-5
As I indicated, this may not be what you wanted, but this is what I thought you were asking.
Alternate version using INDEX function
=INDEX(A2:R2,MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0))-INDEX(A2:R2,MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),DATE(YEAR(A1:R1),MONTH(A1:R1),1),0)-5)
The above would also be entered as an array formula.

Calculate the week number of a given date using a given a reference year

I have a formula which calculates the week number of a given date:
=WEEKNUM(Sheet2!N83)
I want a formula which returns the week number using 2018 as reference, in a similar manner as the above formula does. If the year is 2019, I want it to return weeknum + 52, so for 2019-01-01 I get week number '53'.
How can I achieve this?
This is only valid for years 2018 and 2019:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(Sheet2!N83)+52)
or:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(DATE(2018,MONTH(Sheet2!N83),DAY(Sheet2!N83)))+52)
You actually need a formula which calculates the difference in weeks.
In A1 cell, fill the first day of the reference year (e.g. 2018-01-01).
In A2 cell, put the day of the week of your interest (e.g. 2019-01-03).
In the A3 cell, use this formula to calculate the difference in weeks (in case your week begins at Mondays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-2), B2, "d") / 7), 0) + 1
Or this one (in case your week begins at Sundays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-1), B2, "d") / 7), 0) + 1

Excel SUMIFS Statement - Calculate profit for each month across multiple years

I've got three columns of data.
Sell Date - Column G - Contains the day, month and year in dd/mm/yyy format.
Month (calculated from sell date) - Column I - Contains month number
Profit - Column M - Profit in Dollars.
I am trying to calculate the profit made in each month and year.
Current formula using SUMIFS. I look at the data in Column I and if this contains a 1, and if G contains the year 2016 then it's January 2016. Think it's the year function that I don't quite get.
=SUM(SUMIFS(M9:M50, I9:I50, {"1"}, G9:G50, YEAR=2016))
You can create another column that shows just the year year(G2) or you can use this formula
=SUMIFS(M9:M50,G9:G50,">=1/1/2016",G9:G50,"<1/2/2016")
I also like this formula that allows you to reference the date in one cell and calculate a 1 month range. Put 01/01/2016 in cell A1 and the formula does the rest.
=SUMIFS(M9:M50,G9:G50,">="&A1,G9:G50,"<" & EDATE(A1,1))
The SUMIFS function doesn't like it when you alter the value of the IF parameters. It would be better to use a SUMPRODUCT formula to calculate this, for example:
=SUMPRODUCT((M9:M50)*(I9:I50=1)*(YEAR(G9:G50)=2016))
Where:
(M9:M50) are the values you wish to SUM.
(I9:I50) are the month values and 1 is the month you wish to specify.
(G9:G50) are the date values you wish to obtain the year from and 2016 is the year you are specifying.

How to find the last 8 quarters and their years from the current quarter and year or a given date

I am trying to find the last 7 quarters from the given quarter and year in MS Excel.
For eg.
if I have Q1 2016 then I should be able to find Q4 2015 in one cell and Q3 2015 in another cell and so on showing the last seven quarters. This should be dynamic i.e when the current quarter changes, the year should move also wherever required.
I have been able to find the last quarter number using the following formulas:
=CHOOSE(CEILING(MONTH(E4)/3,1),1,2,3,4)
and
=IF(F5-1=0,4,F5-1)
But I am not able keep the year dynamic.
If the current quarter is Q1 2015 then the quarters I need would be:
Q4 2015
Q3 2015
Q2 2015
Q1 2015
Q4 2014
Q3 2014
Q2 2014
Your question is not clear. But, with some date in E4, the following formula will return Qn YYYY. If you then fill right, it will return the preceding quarters. If your layout is different, you will need to adjust the formula accordingly.
EDIT Formula adjusted to be able fill right instead of down
F5: ="Q" & INT(MONTH(EDATE($E$4,-(COLUMNS($A:A)-1)*3))/3)+1 &" " & YEAR(EDATE($E$4,-(COLUMNS($A:A)-1)*3))
The formula subtracts a multiple of 3 months from the date in E4; and computes the quarter and year for that date. By using the ROWS function, that multiple is incremented each time you fill down one row.

Resources