I have provided a simple example of what I would like to do. I tried to use AverageIf to get the average of all Monday sales for March and April but the formula only provides me the average of March's Monday sales and excludes April.
Note: Column A is Weekday number, Column B is March Sales, Column C is April Sales.
This is the formula I used:
=AVERAGEIF(A2:A200, "=" & 1, B2:C200), which only provides me with average Monday sales in column B.
How can I adjust the formula to also include April in the total average (i.e. take into account column C rather than just column B alone)
Rather than using AverageIf(), try using Average(If()) as an array formula for this kind of scenario.
In your scenario, you could use the following formula to get the average:
=AVERAGE(IF(A2:A200=1,B2:C200))
ENTERED AS AN ARRAY FORMULA using cntrl + shift + enter
Hope that helps.
Related
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.
I have a spreadsheet that tracks average file processing times over the course of a month. One of the macros and stats that we like to pull, is performance on Mondays (as the files are a little built up over the weekend). The spreadsheet is organized into columns by weekdays of the month:
The dates are formatted MM/DD/YYYY, so I would think Excel has a date function that it can determine weekday based on that date value.
Currently, I just have to manually tell the Macro which columns are Mondays, like so:
=AVERAGE(B20,G20,L20,Q20)
So, instead of manually, how would I get the average over the range of say, B20 to V20, only if the day of the week is Monday (the date cells are in row 1, so B1 to V1)?
To determine the weekday of a date in EXCEL use the =WEEKDAY() formula, which evaluates as 1 (Sunday) to 7 (Saturday)
e.g. If A1 contains 12/31/2016 (or 31/12/2016 if you're from where I'm from), the formual =WEEKDAY(A1) would evaluate to 7 (indicating that the last day of 2016 was a Saturday)
To apply this formula to your problem: (assuming that the dates are in row 1 and the values are in row 2)
insert a new row to hold the WEEKDAY() value (say, row 2)
in cell A2 type in =WEEKDAY(A1)
copy this formula as far right as necessary (to include all your dates)
Your average for Mondays is calculated as =AVERAGEIF(2:2, 2, 3:3)
Possibly, you can add a column called [Day Of The Week] and use the following formula to display the day.
TEXT(B4,"dddd")
Then add an 'If'statement to your result cell.
simply
=SUMPRODUCT((MOD(B1:V1,7)=2)*B20:V20)/SUMPRODUCT((MOD(B1:V1,7)=2)*1)
should give the average of all values from B20 to V20 if the corresponding cell in row 1 is a monday.
the first part sums the values of all mondays and the second part counts them (sum / count = average) ;)
If you have any questions, just ask.
If your date is in A1, you can use =Text(A1,"dddd") to determine the day of the week (it will return the name, "Monday", "Tuesday", etc.) so then you could do perhaps:
=If(text(A1,"dddd")="Monday",[do whatever],[do whatever]) (may need a helper row/column to hold the text of the weekday)
(Or use AverageIf() and use the Text() idea.)
Assume that we are currently in the month March. I have a table with all the months and a list of products. Inside each column i have the number sales a product has made on that month, like so:
Notice i have a cell containing "Total until current month". I would require a formula to find out the total amount of sales of a specific product (product A for example) up until March (current month) as you can see with the manually typed 6, 1 in Jan and 5 in Feb.
I would usually do this by finding the sum of cell C4 and D5. But this should be 1 dynamic formula that is updating as we progress onto next month. So as an exammple, in April, it will find the sum of cell C4 - E5 (Jan - March) and update the value.
Is this possible?
Regards
Put a helper row above the month names that has the month numbers 1-12.
Then use SUMIFS():
=SUMIF($C$2:$N$2,"<=" &MONTH(TODAY()),C4:N4)
You could hide that row so it is not visible and not readily accessible.
In row 3 put month numbers. Now if in cell Q4 you have a month number that you want to relate to use:
=SUMIF($C$3:$N$3,"<"&$Q$4,C5:N5)
for sum of A and drag down for other products.
If you want to pick the product you want sum for and have it all in one cell, then assuming that in cell R4 you have your product name (e.g. "B") write
=SUM((C3:N3<Q4)*C5:N6*(B5:B6=R4))
and press ctrl+shift+enter.
The simplest solution is to leave E4 through N4 empty. Only put a value in E4 once March is complete and you have a value for March. This will allow a formula like:
=SUM(C4:N4)
for Product A
In sheet "Dividends" I have a table with dividends sorted by daily dates. E.g, columns A and B contain the following entries:
6/14/2015
6/13/2015
6/12/2015 0.045
6/11/2015
6/10/2015
This means that the stock paid a dividend of 0.045 on 6/12/2015.
In another sheet "AdjClose", I have a table with weekly dates and stock prices, e.g.
6/15/2015 1.23
6/8/2015 1.24
6/1/2015 1.06
5/30/2015 1.10
5/23/2015 1.22
5/16/2015 1.20
I would now compute the yield, where I divide the dividend by the stock price that is closest to the date of the dividend payout, but smaller than that date.
The result should be:
0.045/1.24
How could I do this? Many thanks for any input.
Following 4 named ranges for simplicity in code:
"Dividends": DividendDates (column A); DividendsPaid (column B)
"AdjClose": StockDate (column A); StockPrice (column B)
try (in column C in "Dividends":
{=INDEX(StockPrice;MATCH(MAX(IF((StockDates<=A1);StockDates));StockDates;0))}
Assuming that the dividend date for which you want to find the adjusted stock price is in cell A1.
And copy down for each dividend date. This will give you the stock price of the day closest to, but before, you dividend date (or on the date if it is the same). Then just devide by your dividend for that day (either in the formula I wrote, or in a separate column. Always good to show your calculations steps, so it is easier to follow.
And remember to press CTRL + SHIFT + ENTER when you enter the formula, not just ENTER, as it is an array formula.
EDIT: Also, you need to change the ; to , if that is the formula separator of your language.
Not the best looking one, but an option:
{=B3/INDEX(AdjClose!$B$1:$B$6,MATCH(MAX((AdjClose!$A$1:$A$6<=Dividends!A3)*AdjClose!$A$1:$A$6),AdjClose!$A$1:$A$6,0))}
Option #2 - much better, as there are no repeating ranges:
{=B3/INDEX(AdjClose!$B$1:$B$6,MATCH(1,--(AdjClose!$A$1:$A$6<=Dividends!A3),0))}
From a list of sales (colmuns A and B), how can I extract the number of sales per day, months, quarter with Excel ? (ie columns D, F, H)
I found some dirty code solution with
=SUM(DECALER(...; (LINE()-2)*31; 0; 31; 1))
(sorry I don't know english's translation for Excel's DECALER function)
but it would very annoying to have to distinguish between months of 30, 31, 28 days, etc.
Do you know a clean solution ?
You can use this formula to count for each month:
=SUMPRODUCT((MONTH($A$1:$A$10)=2)*(YEAR($A$1:$A$10)=2013))
And this for quarters:
=SUMPRODUCT((MONTH($A$1:$A$10)>=1)*(MONTH($A$1:$A$10)<=3)*(YEAR($A$1:$A$10)=2013))
I assume dates in A1:A10, the quarter example is for first quarter, for second replace 1 by 4 and 3 by 6
Pivot Tables are the easy answer to this.
But you could inesrt 2 columns after the date
and use this forumula to get the month name
=TEXT(A2,"mmm")
In the other column use this formula to get the Quarter
=ROUNDUP(MONTH(A2)/3,0)
Then you can use COUNTIF or SUMIF depening on what you need to get your totals
Thanks to the two proposed answers given by StevenMartin and CRondao, here is what might be the simplest solution :
= COUNTIFS($A:$A; ">=" & C2;$A:$A; "<" & C3 )
This can be copied in all cells of column D and F (and also cells of H, provided I replace Q3, Q4 quarter names by the date of the beginning of each quarter).