Categorizing data in Excel using formula - excel

I am trying to classify each row as x, y, or z based on both a month and day (a certain time of the year). My categories are:
X = June 1st - October 1st
Y = November 15th - April 15th
Z = All others
I realize this may be simple, but I can't seem to get the formula just right. The table I have looks like:
Day Month Year Test
7 5 2012 Z
6 5 2013 Z
2 11 2011 Z
4 6 2013 Z
27 5 2013 Z
14 3 2013 Z
14 5 2014 Z
20 10 2013 Z
5 12 2013 Z
My current formula for "Test" is:
=IF(AND(AND(B2>=6,A2>=1),AND(B2<=10,A2<=1)),"X",IF(OR(AND(B2<=4,A2<=15),AND(B2>=11,A2>=15)),"Y","Z"))
Any help would be appreciated!

The reason your formula isn't working is that you are testing for both month and day at the same time - for example,
IF(AND(B2<=4,A2<=15)
will return false for March 16, even though you want it to be true. This is because your formula doesn't understand the concept of "days and months".
The formula I would use is
=IF(AND(DATE(C2,B2,A2)>=DATE(C2,6,1),DATE(C2,B2,A2)<DATE(C2,10,1)), "X",
IF(OR(DATE(C2,B2,A2)>=DATE(C2,11,15),DATE(C2,B2,A2)<DATE(C2,4,15)), "Y", "Z"))
Note - I added an carriage return that shouldn't really be there to make it more readable.
Note also that my formula computes DATE(C2,B2,A2) a number of times, and it might be good to have that as a separate (hidden) column. The nice thing about this expression is that it uses the built in DATE function which understands about months and days - and it's relatively easy to fix it depending on what the date range criteria are. With your test dates, it gives the following:
Day Month Year Test
7 5 2012 Z
6 5 2013 Z
2 11 2011 Z
4 6 2013 X
27 5 2013 Z
14 3 2013 Y
14 5 2014 Z
20 10 2013 Z
5 12 2013 Y
Note - updated after #pnuts pointed out error...
Also note... there are a total of 4 conditions in the above - and I took some liberty in deciding what dates to include. Basically, I translated your requirements as follows:
date >= Nov 15 of this year ==> "Y"
date < April 15 of this year ==> "Y"
date >= June 1 AND date < Oct 1 ==> "X"
else "Z"
This may not be exactly what you wanted but it should be obvious how the expressions work, and you should be able to adjust as needed (in particular it was not clear if the 15th of April should be part of "Y" or "Z", for example.)
I think it would be useful to define a series of variables (maybe on a hidden sheet)
startXmonth = 4
startXday = 15
stopXmonth = 10
stopXday = 1
etc, and then you can use these names instead of "magic numbers" in your formula. That way, if you decide you want to change the range of dates corresponding to a particular tariff, you can change it in a sensible place, rather than somewhere buried in a formula. You may think it is extra work now, but you will thank me later...
Finally, you might want to make all the dates "Up to and including" - using <= and >=, and defining the first and last day (rather than, as above, the first day to include and the first day not to include).
Let me know if this all makes sense.

Untested (expected results would have helped) please try:
=IF(OR(AND(B2<5,A2<16),AND(B2=11,A2>14),B2=12),"Y",IF(OR(AND(B2>5,B2<10),AND(B2=10,A2=1)),"X","Z"))

Related

count and sum function not properly working

I am working in excel and for some reason my sum or count function is not working properly. Or, perhaps I am not using the correct function or in the right way.
A B C D E F G H
February Max March Max
1 28
2
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
IF(SUM(E:E>0),31,"")
I have the above columns, I want the Max columns to show a specific number only if there is data in their respective month column. February has data, so it shows 28. March does not have any data so it shows no max. I need to look at the entire column or at least a large area (row 2 to row 2000).
The issue I am having is that if I do not have a value in the first row, but do have values in later rows, the sum or count function will to recognize that and will return zero.
A B
February Max
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
I have tried both sum and count functions, neither are giving me the results I want. I have also tried making >= 1. I found from StackExchange that someone was having a similar problem and a solution was to change the cell format to a number. That did not work either. Any suggestions?
Per my comment, you could use COUNTA() which checks if a cell is blank.
While it doesn't answer the technical reason SUM/COUNT isn't working, it should work for your intended purposes.
=IF(COUNTA(A:A)>0,28,"")

Excel formula to Increment every after X Number of Years

I would like to Add an Increment of One on Every X Year Interval
For Example if X = 3 Then the Following Data should be
SG Last Year
5 2010
4 2014
3 2015
6 2016
Would result to
Grp Last Year 2016 2017 2018 2019 2020
5 2010 6 6 6 7 8
4 2014 4 5 5 5 6
3 2015 3 3 3 4 4
6 2016 6 6 6 7 7
So the First Record the Candidate is in group 5, from 2010, in 2016 I would like to calculate if the candidate has a span of at least 3 years if so, push him to 1 upper group which is 6. The Same Candidate will go through n Number of years and every 3 years (X Number of Years) would increment their group till we reach to 1 and continues with 1 without any increment. Thus is the same example since we increment in 2016, the candidate would have the same group for the next 3 years and only in 2019 would we increment again and so on.
I would like and excel formula or process which I could use for the data set proposed
You were almost there.
LY = Last year (that static cell in each row);
AY = Active year (the column for which you are calculating),
G = group (start value),
PR = previous result (for prev year),
R = result (what you want to get),
X = year interval`
You can use one formula for first year (2016) and another for the rest, so you can use previous value PR, not initial group G.
Obviously LY stays constant for the row.
R = IF (( (AY-LY) \ X)==0 , PR+1, PR) - change when mod is 0.
Use #3 formula for all the years except first column (2016).
For first column (2016) instead of PR you should use G.
To have a constant cell, you write in form of $A$1 (for G)
For constant row you write in form of C$0 (for AY)
Your formula was almost correct. And you need to set the values constant where they need to be.

Determine number of days within a date range across multiple years

I hope I can explain this properly. I need to calculate occupancy time for a population of migratory animals. Occupancy is defined as the period, in days, between the first and last sighting of an individual in a given year between 1999 and 2015. A sample of the type of sighting data I am dealing with is pasted below. I need to be able to calculate the number of days between sightings within a year and NOT between the first and last sightings or between each sighting. Further, I need a value of "1" if the animal was only seen once in that year, rather than a value of "0".
So, for example, based on individual 37 in the data below, the results table would look something like
1999 - 0 2000 - 11 2001 - 40 2002 - 2 2003 - 0
1999 - 0
2000 - 11
2001 - 40
2002 - 1
2003 - 0
2004 - 52
2005 - 1
...and so on.
I have tried this series of equations but it does not return the right values for the years in which an animal was seen only once and it ignores any years prior to the first year seen.
in cell K2:
=DATE(YEAR(MIN($B$2:$J$2)),1,1)
in cell L2:
=IF(N(K2)=0,"",MAX(MAX(IF($B$2:$J$2=K2,$B$2:$J$2)),0))
in cell M2:
=IF(N(K2)=0,"",IF(MAX($B$2:$J$2)>DATE(YEAR(K2)+1,1,1),DATE(YEAR(K2)+1,1,1),""))
so if more than 1 year between sightings then it should be 0?
and is that more than "365 days a year" or if it is spotted 1 time 1. december and 1 time 1. januar then its still only spotted 1 time pr year...
I was able to find a solution using this equation in the cells immediately following the last sighting.
=IF(COUNTIFS($B2:$V2,">="&DATE(BE$1,1,1),$B2:$V2,"<="&DATE(BE$1,12,31))>0,LOOKUP(DATE(BE$1,12,31),$A2:$V2)-INDEX($A2:$V2,MATCH(DATE(BE$1,1,0),$A2:$V2)+1)+1,0)

Including start year and end year in YEAR calculations

For the calculation I'm trying to perform one year = one season and the data I have is start year and end year.
So 1952 1953 needs to add up to 2 (seasons) but if I use =YEAR(A1)-YEAR(A2) the result is 0 - is there a simple way to include the start year and end year as a value in these calculations?
It looks like you have found the problem and rectified it. For the benefit of others who might have found this thread, this is why it was behaving the ways it was.
Background - Excel (and many other applications) treat dates as 1 for every day past Dec 31, 1899. Today happens to be 42,079. Time is a decimal portion of a day so 42,079.75 would be Mar 16, 2015 06:00 PM.
You had the years as numbers in A1:A2; not as full dates. Using the 1-per-day formula, 1952 is May 5, 1905 and 1953 is May 6, 1905. If you peel out the year of each of those with the YEAR() function, you are subtracting 1905 from 1905; resulting in zero.
The solution would be to either type full dates into A1:A2 and format the cells as yyyy so they display 1952 & 1953 but retain their full date nature e.g. =ABS(YEAR(A1) - YEAR(A2)) + 1 , or use the years as numbers only and discard the YEAR() function altogether, e.g. =ABS(A1 - A2) + 1 to get the spanned (inclusive) number of seasons.

Excel: Count billing hours for specific month, week, year

I have four columns in a spreadsheet, Month, Week, Year, Hours and I want to 'sum' the number of hours based on the month, week, and year number. Months would be (1-12), week would be (1-52), and year would be (2009, 2010, 2011)
For example:
Month Week Year Hours Total_Hours
1 2 2011 8 12
1 2 2011 4 12
1 2 2010 7 7
1 2 2009 5 5
Not sure if I should use vlookup or a nest 'if'. If someone else has a better approach, please let me know.
Thanks in advance.
First, you create another column that is a string concatenation of the first three, and drag down:
=TRIM(A2) & TRIM(B2) & TRIM(C2)
Then, you use this formula for Total_Hours, and drag down:
=SUMIF(D:D, D2, E:E)
My example uses your sample, and inserts a new column D for the concatenation.
End Result:
Month Week Year Concat Hours Total_Hours
1 2 2011 122011 8 12
1 2 2011 122011 4 12
1 2 2010 122010 7 7
1 2 2009 122009 5 5
Of course, I'd use Named Ranges for anything that's likely to change.
If you use VLOOKUP ensure the textual data is formatted correctly or use Text and Data functions

Resources