I have excel data in following format.
Date Amount
03-Jan-13 430.00
25-Jan-13 96.00
10-Jan-13 440.00
28-Feb-13 72.10
28-Feb-13 72.30
I need to sum the amount field only if the month lies in Jan Month.
What i have tried is ,
=SUMIF(A2:A6,"MONTH(A2:A6)=1",B2:B6)
But it returns,
0
What i need is,
Following values to be summed, 430.00 + 96.00 + 440.00 = 966.00
Try this instead:
=SUM(IF(MONTH($A$2:$A$6)=1,$B$2:$B$6,0))
It's an array formula, so you will need to enter it with the Control-Shift-Enter key combination.
Here's how the formula works.
MONTH($A$2:$A$6) creates an array of numeric values of the month for the dates in A2:A6, that is, {1, 1, 1, 2, 2}.
Then the comparison {1, 1, 1, 2, 2}= 1 produces the array {TRUE, TRUE, TRUE, FALSE, FALSE}, which comprises the condition for the IF statement.
The IF statement then returns an array of values, with {430, 96, 400.. for the values of the sum ranges where the month value equals 1 and ..0,0} where the month value does not equal 1.
That array {430, 96, 400, 0, 0} is then summed to get the answer you are looking for.
This is essentially equivalent to what the SUMIF and SUMIFs functions do. However, neither of those functions support the kind of calculation you tried to include in the conditional.
It's also possible to drop the IF completely. Since TRUE and FALSE can also be treated as 1 and 0, this formula--=SUM((MONTH($A$2:$A$6)=1)*$B$2:$B$6)--also works.
Heads up: This does not work in Google Spreadsheets
=Sumifs(B:B,A:A,">=1/1/2013",A:A,"<=1/31/2013")
The beauty of this formula is you can add more data to columns A and B and it will just recalculate.
=SUMPRODUCT( (MONTH($A$2:$A$6)=1) * ($B$2:$B$6) )
Explanation:
(MONTH($A$2:$A$6)=1) creates an array of 1 and 0, it's 1 when the
month is january, thus in your example the returned array would be [1, 1, 1, 0, 0]
SUMPRODUCT first multiplies each value of the array created in the above step with values of the array ($B$2:$B$6), then it sums them. Hence in
your example it does this: (1 * 430) + (1 * 96) + (1 * 440) + (0 * 72.10) + (0 * 72.30)
This works also in OpenOffice and Google Spreadsheets
Related
Fellow overflowers, all help is appreciated;
I have the following rows of values (always 7 values per row) of data in Excel (3 examples below), where data is coded as 1 or 2. I am interested in the 1's.
2, 2, 1, 2, 2, 1, 1.
1, 2, 2, 2, 2, 1, 2.
2, 2, 2, 1, 1, 1, 2.
I use the =MATCH(1,A1:G1,0) to tell me WHEN the first 1 appears, BUT now I want to calculate the proportion that 1's make up of the the remaining values in the row.
For example;
2, 2, 1, 2, 2, 1, 1. (1 first appears at point 3, but then 1's make up 2 out of 4 remaining points; 50%).
1, 2, 2, 2, 2, 1, 2. (1 first appears at point 1, but then 1's make up 1 out of the 6 remaining points; 16%).
2, 2, 2, 1, 1, 1, 2. (1 first appears at point 4, but then 1's make up 2 out of the 3 remaining points; 66%).
Please help me calculate this proportion!
You could use this one
=(LEN(SUBSTITUTE(SUBSTITUTE(MID(A1,SEARCH(1,A1)+3,1000)," ",""),",",""))
-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(MID(A1,SEARCH(1,A1)+3,1000)," ",""),",",""),1,""))
)/LEN(SUBSTITUTE(SUBSTITUTE(MID(A1,SEARCH(1,A1)+3,1000)," ",""),",",""))
The
SUBSTITUTE(SUBSTITUTE(MID(A1,SEARCH(1,A1)+3,1000)," ",""),",","")
-part gets the string after the first 1. The single 1 in the middle part is the one, you want to calculate the percentage for. So if you want to adapt the formula to other chars, you have to change the single 1 in th emiddle part and the three 1s in the three searches.
EDIT thank you for the hint #foxfire
A solution for values in columns would be
=COUNTIF(INDEX(A1:G1,1,MATCH(1,A1:G1,0)+1):G1,1)/(COUNT(A1:G1)-MATCH(1,A1:G1,0))
You can do it with SUMPRODUCT:
My formula in column H is a MATCH like yours:
=MATCH(1;A3:G3;0)
My formula for calculatin % of 1's over reamining numbers after first 1 found, is:
=SUMPRODUCT((A3:G3=1)*(COLUMN(A3:G3)>H3))/(7-H3)
This is how it works:
(A3:G3=1) will return an array of 1 and 0 if cell value is 1 or not. So for row 3 it would be {0;0;1;0;0;1;1}.
COLUMN(A3:G3)>H3 will return an array of 1 and 0 if column number of cell is higher than column number of first 1 found, (that matchs with its position inside array). So for row 3 it would be {0;0;0;1;1;1;1}
We multiply both arrays. So for row 3 it would be {0;0;1;0;0;1;1} * {0;0;0;1;1;1;1} = {0;0;0;0;0;1;1}
With SUMPRODUCT we sum up the array of 1 and 0 from previous step. So for row 3 we would obtain 2. That means there are 2 cells with value 1 after first 1 found.
(7-H3) will just return how many cells are after first 1 found, so fo row 3, it means there are 4 cells after first 1 found.
We divide value from step 4 by value from previous step, and that's the % you want. So for row 3, it would be 2/4=0,50. That means 50%
update: I used 2 columns just in case you need to show where is the first 1. But in case you want a single column with the %, formula would be:
=SUMPRODUCT((A3:G3=1)*(COLUMN(A3:G3)>MATCH(1;A3:G3;0)))/(7-MATCH(1;A3:G3;0))
Let's say I have the following two columns in excel spreadsheet
A B
1 10
1 10
1 10
2 20
3 5
3 5
and I would like to sum the values from B-column that represents the first occurrence of the value in A-column using a formula. So I expect to get the following result:
result = B1+B4+B5 = 35
i.e., sum column B where any unique value exists in the same row but Column A. In my case if Ai = Aj, then Bi=Bj, where i,j represents the row positions. It means that if two rows from A-column have the same value, then its corresponding values from B-column are the same. I can have the value sorted by column A values, but I prefer to have a formula that works regardless of sorting.
I found this post that refers to the same problem, but the proposed solution I am not able to understand.
Use SUMPRODUCT and COUNTIF:
=SUMPRODUCT(B1:B6/COUNTIF(A1:A6,A1:A6))
Here the step by step explanation:
COUNTIF(A1:A6, A1:A6) will produce an array with the frequency of the values: A1:A6. In our case it will be: {3, 3, 3, 1, 2, 2}
Then we have to do the following division: {10, 10, 10, 20, 5, 5}/{3, 3, 3, 1, 2, 2}. The result will be: {3.33, 3.33, 3.33, 20, 2.5, 2.5}. It replaces each value by the average of its group.
Summing the result we will get: (3.33+3.33+3.33) + 20 + (2.5+2.5=35)=35.
Using the above trick we can just get the same result as if we just sum the first element of each group from the column A.
To make this dynamic, so it grows and shrinks with the data set use this:
=SUMPRODUCT($B$1:INDEX(B:B,MATCH(1E+99,B:B))/COUNTIF($A$1:INDEX(A:A,MATCH(1E+99,B:B)),$A$1:INDEX(A:A,MATCH(1E+99,B:B))))
... or just SUMPRODUCT.
=SUMPRODUCT(B2:B7, --(A2:A7<>A1:A6))
I have a formula which gives me different dates depending on the multiplier. I am not sure how it works though, except that it rounds a date. The formula is the following:
=DATE(YEAR($L$4),CEILING(MONTH($L$4),2),0)
So imagine today´s date is 18/08/2015 in cell L4. If i change the multiplier i get the following results:
=DATE(YEAR($L$4),CEILING(MONTH($L$4),2),0) = 31/07/2015
=DATE(YEAR($L$4),CEILING(MONTH($L$4),3),0) = 31/08/2015
=DATE(YEAR($L$4),CEILING(MONTH($L$4),4),0) = back again to 31/07/2015.
Why does this happen? Why does it go back to 31/07/2015 if the multiplier increases to 4?
=CEILING('number', 'multiple') returns a multiple of the 'multiple' that is nearest to the 'number'.
Since MONTH evaluates to 8 or August, you would have =CEILING(8, 3), which evaluates to 9, because 9 is the multiple of 3 closest to 8. 2 and 4 as multiples will both return 8.
=DATE(2015, 9, 0) will return the last date of the previous month, because the day is 0.
If you tried your formula with CEILING(MONTH($L$4), 10), you would get 31/9/2015, because the multiple of 10 nearest to 8 is 10, and the DATE formula will end up looking like =DATE(2015, 10, 0) which evaluates to 31/9/2015.
As a side note, the button below is very helpful in analyzing the formulas that you select in the excel chart.
I have a data set with four columns: Start Date, End Date, Scheduled Qty, and Actual Quantity:
Start Date End Date Scheduled Qty Actual Qty
04/13/15 04/17/15 35 19
04/20/15 04/24/15 35 42
04/27/15 05/01/15 35 41
05/04/15 05/08/15 35 41
I want to find the total actual, except when the actual exceeds the scheduled I want to used the scheduled number.
In an already answered question (Sum minimum of corresponding column values) I found an array formula that works to total the lesser values of each row for the Qty columns (quotes used to display the less than symbol):
=SUM(IF(C1:C4"<"D1:D4, C1:C4, D1:D4))
This gives me a total for my whole range, but now I'd like to limit it to a date range such as end dates within a given month. I've used SUMIFS in other situations to look at my end dates and only sum data that falls within a given month, but I'm not figuring out how to combine that idea with the one from the array formula.
Any ideas how to make this happen? I'm working in Excel 2013.
Here's an extension of chancea's approach:
Excel's SUM function (and AVERAGE, STDEV, etc.) have the useful behavior of "skipping" over text values. For example AVERAGE(3, 4, "dog", 5) returns 4. You can leverage this behavior nested IF's inside a sum. For instance,
=SUM(IF(MONTH(B1:B4)=4,IF(C1:C4<D1:D4,C1:C4,D1:D4),"NO"))
will sum
(a) the lesser of scheduled and actual
(b) when the month is 4
This is accomplished by nested IF's. The outer IF is
IF(MONTH(B1:B4)=4,...,"NO") [if month <> 4, IF returns text ("NO"), which SUM skips]
The inner IF is the same one that chancea showed.
You can nest as many tests/filters for your data as you need
To add criteria onto an array function most of the time you are just going to be multiplying the extra condition onto whatever set of conditions you already have.
The reason why this works is simply because we start with our list of numbers we want to sum:
IF(C1:C4<D1:D4, C1:C4, D1:D4) => { 19, 35, 35, 35 }
Then we multiply 1's or 0's to each of the values that meet the extra criteria.
So for an example lets say that we only want to check the quantity of values that have an end date within the month of 4. We can do that with:
MONTH(B1:B4)=4
Just multiply that criteria in the SUM function to basically create a boolean and condition for that criteria:
=SUM(IF(C1:C4<D1:D4, C1:C4, D1:D4)*(MONTH(B1:B4)=4))
= SUM({ 19, 35, 35, 35 } * { 1, 1, 0, 0}) => SUM( {19, 35, 0, 0} ) = 54
This is the same if we want to add n condition's:
=SUM(IF(C1:C4<D1:D4, C1:C4, D1:D4)*(MONTH(B1:B4)=4)*(`Condition2`)*(`Condition3`)...)
You can use any formula or operator that returns a true/false value within your conditions.
Such as: = > < >= <= <> IF(...,TRUE)
To add OR logic as a criteria you need to use addition instead of multiplication and then group them inside a (..)>0 like this:
(((Or_Condition1)+(Or_condition2)+...+(Or_conditionN))>0)
So if we wanted to sum months 4 OR 5 we can write:
=SUM(IF(C1:C4<D1:D4, C1:C4, D1:D4)*(((MONTH(B1:B4)=4)+(MONTH(B1:B4)=5))>0))
Trying to do an if else statement, if the results of the index query is greater than the other. I want it to go like this:
If index query / index query's result is greater than 1, multiply the formula by the percentage it is greater than 1.
For example
If 10 / 5 is greater than 1, multiply it by the sum of (4 * 3), else, don't multiply it and just do the sum.
=IF(
INDEX(AK:AK,MATCH($A3,M:M,0))>INDEX(AL:AL,MATCH($A4,M:M,0)),
SUM(B12*E13*R24)*(INDEX(AK:AK,MATCH($A3,M:M,0),SUM(B12*E13*R24)))
)
not getting anywhere with this.
It seems that this can be reduced down to multiplying your base calculation by either 1 or the quotient of the two lookups when their quotient is greater than 1.
=B12*E13*R24*MAX(INDEX(AK:AK,MATCH($A3,M:M,0))/INDEX(AL:AL,MATCH($A4,M:M,0)), 1)