Explain the CEILING function for dates - excel

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.

Related

How to compare hours with numbers in excel?

I am making a task sheet for my students and I have written the following code:
=IF(J35-K35>5,"Task 1",IF(J35-K35>3,"Task 2",IF(J35-K35>2,"Task 3", IF(J35-K35>0,"Task 4",IF(K35-J35<1,"Task 5",IF(K35-J35<3,"task 6",IF(K35-J35>3,"Task 7")))))))
The cell K35 contains "Total hours worked" and
The cell J35 contains "Total hours required".
Their format is in [h]:mm
The problem I am facing here is that it is showing me output for only 2 conditions - for the one which is greater than 0 (Task 4) and the other which is less than 1 (task 5). None of the other conditions are getting executed. I need a way in which I can compare hours with numbers.
How can I solve this problem?
If the cells contain times, the calculation J35-K35 will return a number between 0 and 1 for a positive value, between -1 and 0 for a negative value. The formula will use the underlying values, not what they will look like if formatted as time.
The value of one hour, formatted as general is 0.041666667. You can either use that and its multiples in your formula or multiply the result of the subtraction by 24 to arrive at numbers where the part before the decimal point is the number of hours, so your formula could be
=IF((J35-K35)*24>5,"Task 1",IF((J35-K35)*24>3,"Task 2",IF((J35-K35)*24>2,"Task 3", IF((J35-K35)*24>0,"Task 4",IF((K35-J35)*24<1,"Task 5",IF((K35-J35)*24<3,"task 6",IF((K35-J35)*24>3,"Task 7")))))))

origin value and after sum after ROUND() is different

I have a table with "ordered amount", "percentages", and "total sum". Note that "ordered amount" and "total sum" should be the same.
column F= sum of C:F
*rows 4,6,8,10 used =round()
As shown in the table(image), for some numbers, value in F is not the same as A when it should be. (e.g. A6(105) and F7(104), -1 after rounding).
Is there anyway to avoid this?
Thank you very much.
If the sum of the decimal points adds up to > 5, your final rounded number will round up. If they add up to < 5, the final number will round down.
Consider this example:
10.5 + 5 = 15.5, which rounds to 16.
However
10 + 5 = 15
This is what is happening in your table.
In order to get the sum of rounded numbers to add up to the same as the sum of the numbers, in your example, you will need to NOT round, but rather subtract, one of the values. I would suggest altering the largest value, as it would seem to have the least effect on the percentages, but that is a choice you can make.
To do that, with your data in row 8, for example you could do the following.
A9: =IF(B$8=MAX($B$8:$E$8),SUM($B$8:$E$8)-SUM(ROUND($B$8:$E$8,0))+ROUND(B$8,0),ROUND(B$8,0))
entered as an array formula with ctrl+shift+enter and fill right to E9.
This would give a sum of 344 which is the same as F8

Sum minimum of corresponding column values - limited to date range

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))

Excel Formula to SUMIF date falls in particular month

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

Excel formula for "result of 2-7 on the die is always treated as if you rolled an 8"

I have a spreadsheet program which rolls twenty-sided dice. Sheet 1 is Rolls and Sheet 2 is Values.
I want to roll a d20, but if it comes up 2-7, fudge it and assume I got 8 instead.
Rolls!A2's function is =RANDBETWEEN(1,20) which returns a random number between 1 and 20 to represent the d20 roll. Values!7E is function which calculates a (non-random) number (currently 13).
Currently, Rolls!C7's function attempts to calculate my result with =Values!E7+Rolls!A2. But I would like to update Rolls!C7 to reflect the fudging. If Rolls!A2 returns numbers 2, 3, 4, 5, 6, or 7, Rolls!C7 would instead be calculated as if it rolled an 8.
Replace Rolls!A2 in your formula with this: IF(AND(Rolls!A2<8, Rolls!A2>1),8,Rolls!A2) this way it will always be at least 8 unless a 1 is rolled.
Or you could do =IF(Rolls!A2=1,1,MAX(Rolls!A2,8))

Resources