sum weekly range in excel - excel

I have following data in excel -
4/2/2002 -0.018255578
4/3/2002 -0.016528926
4/4/2002 0
4/5/2002 -0.016806723
4/8/2002 0.004273504
4/9/2002 -0.006382979
4/10/2002 0.002141328
4/11/2002 -0.004273504
...
I need to sum all entries of 2nd column that fall on Monday. I am using the following formula but it doesn't work-
=SUMPRODUCT(IF(WEEKDAY(A2:A15)=2,1,0),B2:B15)
A related question - how do I select the dates falling on monday from the given list and copy it to a column with a formula?
Any ideas?
thanks

Here is a formula that will do the first question:
=SUMPRODUCT((WEEKDAY(A1:A8)=2)*B1:B8)
This assumes that your data starts in A1. Adjust your ranges accordingly. You can also use an array formula:
=SUM((WEEKDAY(A1:A8)=2)*B1:B8)
I'm not sure that I understand the second part, which may be why your question is getting voted down.

Related

How to filter out long term events that fall between two dates in Excel 2010?

I'm trying to filter out events that may fall between a certain time period. These events are more than one day, so they have start dates and end dates.
I think the closest example to what I'm looking for is from this link: https://www.extendoffice.com/documents/excel/4647-excel-extract-records-between-two-dates.html. The only difference is that the data in Sheet 1 also have a start and end date that are greater than a day in difference, rather than existing for a singular day.
=IF(ROWS(A$5:A5)>$C$2,"",INDEX(Sheet1!A$2:A$22,SMALL(IF((Sheet1!$A$2:$A$22>=$A$2)*(Sheet1!$A$2:$A$22<=$B$2),ROW(Sheet1!A$2:A$22)-ROW(Sheet1!$A$2)+1),ROWS(A$5:A5))))
The issue is that currently the start dates may not coincide with the bounds of the study dates, but that the end dates of the data in Sheet 1 do fall within these bounds.
An example of what I'm hoping to do is this:
Example:
However, instead of having the date just be a single day, I'm hoping for a way to sort through data that have a start and end date.
This solution seems to work:
Assuming in Sheet1, columnA and columnB contain Start and End dates respectively.
Change the formula in C1 of Sheet2 to this, and follow the other instructions as given in your example.
=SUMPRODUCT((Sheet1!$A$2:$A$22>=A2)*(Sheet1!$A$2:$A$22<=B2)*(Sheet1!$B$2:$B$22>=A2)*(Sheet1!$B$2:$B$22<=B2))
Note: If this is not the output you expect then please share your expected input and output instead of from the sample.
Edit:
Based on your sample image I have updated the formulas. Hope this helps.
Formula for cell H2:
=SUMPRODUCT((($B$2:$B$16>=F2)*($B$2:$B$16<=G2)*($C$2:$C$16>=F2)*($C$2:$C$16<=G2))+((B2:B16<F2)*(C2:C16>=F2)*(C2:C16<=G2))+((B2:B16>=F2)*(B2:B16<=G2)*(C2:C16>G2))+((B2:B16<F2)*(C2:C16)>G2))
Formula for cell F5:
=IF(ROWS(F$5:F5)>$H$2,"",INDEX(B$2:B$16,SMALL(IF((($B$2:$B$16>=$F$2)*($B$2:$B$16<=$G$2)*($C$2:$C$16>=$F$2)*($C$2:$C$16<=$G$2))+(($B$2:$B$16<$F$2)*($C$2:$C$16>=$F$2)*($C$2:$C$16<=$G$2))+(($B$2:$B$16>=$F$2)*($B$2:$B$16<=$G$2)*($C$2:$C$16>$G$2))+(($B$2:$B$16<$F$2)*($C$2:$C$16)>$G$2),ROW(B$2:B$16)-ROW($B$2)+1),ROWS(F$5:F5))))
Don't forget to press Shift + Ctrl + Enter when using formula in F5.
And then extend to other cells.
Output:

excel Sum every other column up to certain month

I have a Simple spreadsheet with 2 rows:
ActualJAN | BudgetJAN | ActualFEB | BudgetFEB | ActualMAR | BudgetMAR ....
100 200 300 400 500 600 ....
I'd like to sum ONLY the Budget columns up to the current month (Month(Today()).
Same for the Actual columns.
So if we're currently in February,
Budget to date would be: 600=200+400
Actual to date would be: 400=100+300
I just can't seem to get there, at least simply and elegantly.
This is a non array formula that performs array like operations. As such large range references should be avoided or you will experience a slow down or potential crash of your system. For a small defined range works great so long as the formula is not repeated too many times either.
Additionally TODAY() is a volitile function which means the formula will recalculate whenever anything in the spreadsheet changes, not just when something related to the formula changes.
This formula is generalized a bit so your data can be located anywhere on your sheet and does not require rearrangement of your data.
To get your actual sum use the following:
=SUMPRODUCT($C$4:$H$4*(COLUMN($C$4:$H$4)-COLUMN($C$4)+1<=MONTH(TODAY())*2)*(LEFT($C$3:$H$3)="A"))
To get your Budget sum use the following:
=SUMPRODUCT($C$4:$H$4*(COLUMN($C$4:$H$4)-COLUMN($C$4)+1<=MONTH(TODAY())*2)*(LEFT($C$3:$H$3)="B"))
Change C4:H4 to suit your number range. ChangeC3:H3 to suit your column title range. Change C4 to be the first cell of your number range.
Caveat: Assumes maximum 12 months starting at January
Proof of concept:
I would recommend structuring your data differently. It would be an easier task if you arrayed everything vertically and divided your data into three columns. The first would be Category, which would be populated with either "Budget" or "Actual." The next column would be Month. After that, of course, you have the Value column. Then, use a basic SUMIF, like "=SUMIF(A1:A6,"Budget",C1:C6)." A1:A6 is the range Excel will scan for the desired variable. In this case, that variable is "Budget." Then, C1:C6 is the value that corresponds to a "Budget" month. That formula will give you the answer you want as long as you expand the SUMIF formula to include the full range of values, e.g., "SUMIF(A1:A317,"Budget",C1:C317)."
So I think I understand what you're trying to do, I cannot make the entire formula without the rest of the spreadsheet but this is working currently:
For the Actual:
=IF(MONTH(TODAY())=1,A2,IF(MONTH(TODAY())=2,A2+C2,IF(MONTH(TODAY())=3,A2+C2+E2,"")))
For the Budget:
=IF(MONTH(TODAY())=1,B2,IF(MONTH(TODAY())=2,B2+D2,IF(MONTH(TODAY())=3,B2+D2+F2,"")))
Here is the spreadsheet I created to test:
If you give me the rest of the data I can complete the formula, basically all you would need to do is add more months to the formula and change the amounts it adds.
I am sure there is probably a more efficient way to accomplish this but this way works.
I suggest a hidden row to control your dates. Say, January is in column C, enter [C1] =1, [D1] =C1, [E1] =C1+1, [F1] =E1. Select E1:F1 and copy to the right until December. Hide row 1.
In row 2 use these two formulas.
[C2] ="Actual" & UPPER(TEXT("1/" & C$1,"mmm"))
[D2] ="Budget" & UPPER(TEXT("1/" & D$1,"mmm"))
Select C2:D2 and copy to the right until December. This exercise isn't required because the resulting display is exactly what you already have. But producing this result with the help of formulas ensures freedom from error, and it is faster. As an added bonus you get a visual check of what's in the hidden row.
Now you can use this formula to extract totals from row 3 where you have your values.
=SUMIFS($C3:$Z3,$C$2:$Z$2,"Budget*",$C$1:$Z$1,"<="&MONTH(TODAY()))
Change "Budget" to "Actual" and the same formula will extract the actual amounts.

SUMPRODUCT several ifs

I´ve spent a lot of time with a formula in Excel and I´m still blocked. I hope you can help me.
I have a table in Excel with several values as shown in this
screenshot.
What I´m trying to extract is the number of Fruits sold in a specific month. That is, how many lemons were sold in January 2016, for example. This is the formula I´m using:
=SUMPRODUCT((B3:B38=E4)*(MONTH($A$3:$A$150)=12)*(YEAR($A$3:$A$150)=2015);$C$3:$C$150)
But the result is #N/A as seen in the screenshot.
What Am I doing wrong? Any help, please?
Thanks a lot in advance!
You can use arrays in excel to get this answer
{SUM(IF(MONTH(F$3&"1")=MONTH($A$3:$A$150),IF($E4=$B$3:$B$150,$C$3:$C$150,0),0))}
You can use this Sumproduct formula which uses array logic:
SUMPRODUCT((MONTH($A$3:$A$38)=MONTH(TEXT(G$2,"MMM")&1))*($C$3:$C$38=$F4)*
($D$3:$D$38))
Sumproduct Demo
Part of your problem is your ranges are not equal in length. B3:B38 has to be the same number of rows as $A$3:$A$150 and C3:C150. When rows are not equal things blow up on you.
=SUMPRODUCT(($B$3:$B$150=$E4)*(MONTH($A$3:$A$150)=12)*(YEAR($A$3:$A$150)=2015);$C$3:$C$150)
if you change your header row to be actual excel date format, and then change the cell display format to just show the month (as suggested by csanjose), then you can adjust your sumproduct formula as follows and copy to all cells in your table.
=SUMPRODUCT(($B$3:$B$38=$E4)*(MONTH($A$3:$A$150)=Month(F$3))*(YEAR($A$3:$A$150)=Year(F$3));$C$3:$C$150)
Fill your month-row with the last day of each month, then apply date format to show only month name.
The formula you should use is, for example, in g8:
=SUMIFS($C:$C;$B:$B;$E8;$A:$A;"<="&G$3;$A:$A;">"&F$3)
First column "F" doesn't have a column on the left to compare, so you can put a date in E3 or change a bit the formula (example of F8):
=SUMIFS($C:$C;$B:$B;$E8;$A:$A;"<="&F$3;$A:$A;">2015/12/31")
Take a look at the result
If you don't want to use a pivot table, you can use this formula to get what you need:
=SUMPRODUCT(($B$3:$B$150=$E3)*(MONTH($A$3:$A$150)=1)*(YEAR($A$3:$A$150)=2015)*$C$3:$C$150)
Then drag-fill the cell to copy it to every month column (just make sure you change the month number in the formula (and year if you're doing that too)), and then drag-fill down the columns.
That should work pretty food good :)
Good Luck!

Sumif Amounts Based on Months for Multiple Months

I have excel data in the following format
Date Amount
01-Jan-16 23.94
12-Jan-16 17.96
26-Jan-16 32.92
03-Feb-16 38.90
20-Feb-16 62.27
26-Feb-16 45.89
I would like to sum the amount field for specific months, that is I would like to sum up the amount in January and also in February separately.
This is the code I have tried thus far which I found in a previously asked question (see Excel Formula to SUMIF date falls in particular month).
=SUM(IF(MONTH(A:A)=1,B:B,0))
It works for January but when I change 1 to 2 it returns zero.
=SUM(IF(MONTH(A:A)=2,B:B,0))
Would sumifs work better?
Here are two other ways of doing it:-
=SUMPRODUCT((MONTH(A2:A10)=1)*B2:B10)
and
=SUMIFS(B2:B10,A2:A10,">="&DATE(2016,1,1),A2:A10,"<"&DATE(2016,2,1))
Change as necessary to get totals for other months.
I have put the results next to the original array formula in this screen shot:-
Use specific range rather than full column. You must use the formula as array formula.
=SUM(IF(MONTH($A$2:$A$1000)=1,$B$2:$B$1000,0))
Press CTRL+SHIFT+ENTER to evaluate the formula as array formula.

EXCEL - how to get the value of the first column in a row in which value in another column meets certain criteria?

I have an excel spreadsheet with the following data
----- A-----------------B
1 ----X
2
3----January 2012-----30
4----February 2012----50
5----March 2012------105
6----April 2012--------140
I would like to set a formula in A1 cell that would give me the value of column A of the first row, where column B has a value higher than 100... in my case the value would be March 2012
I know I am supposed to use VLOOKUP function, but I never used it and it is kinda science fiction for me... specially because I need to put a conditional in there
please help
As per my comment....
You can use this formula based on your jpeg in comment above
=INDEX(A3:A12;MATCH(TRUE;B3:B12>100;0))
confirmed with CTRL+SHIFT+ENTER
or you can throw in an additional INDEX so that the formula can be entered normally, i.e.
=INDEX(A3:A12;MATCH(TRUE;INDEX(B3:B12>100;0);0))
Try this
=CHOOSE(SUM(MATCH(100,B3:B6)+1),A3,A4,A5,A6,A7)

Resources