Excel formula to Increment every after X Number of Years - excel

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.

Related

Excel: how to average with condition

We have an Excel sheet in which we collect some monthly data.
Each line contains a date and some value (in my boiled-down example here the date is always the first of each month and the values are [1..n]).
I am now trying to calculate an average of the values but not from ALL values but only those from the last quarter (i.e. where Date is >TODAY()-90).
TODAY() at the time of this writing is Jan. 30th, 2023, so I would expect the result to be 12, i.e. the average of the values for the last 3 months (11, 12, and 13).
A B
1 Date Value
2 01.01.2022 1
3 01.02.2022 2
4 01.03.2022 3
5 01.04.2022 4
6 01.05.2022 5
7 01.06.2022 6
8 01.07.2022 7
9 01.08.2022 8
10 01.09.2022 9
11 01.10.2022 10
12 01.11.2022 11
13 01.12.2022 12
14 01.01.2023 13
15
16 Avg. last 3 months:
17 #VALUE! <-- =AVERAGE(IF(A2:A14>(TODAY()-90);B2:B14;0))
18 #DIV/0! <-- =AVERAGEIF(A2:A14;">(TODAY()-90)";B2:B14)
I tried several approaches using AVERAGE(...) and AVERAGEIF(...) functions as shown above (and also several other variants) but I could not manage to get this working. All I ever get are error messages like #VALUE! or #DIV/0! :-(
Any idea how I can convince AVERAGE(IF) to only consider those values where the date is >today-90 days?
As per my comment:
=AVERAGEIF(A2:A14,">="&TODAY()-90,B2:B14)
Where the ampersand calculations operator is just a less-verbose way to concatenate different values. Here the 2nd parameter takes a string so using both parts on the left and right of the operator we create a value such as ">=12345".

Addition for two dimensional Excel

I needed some help with conditional addition in Excel.
This is an example data:
A B C D
1 Animal January February March
2 Cat 5 6 7
3 Cat 2 3 5
4 Dog 1 4 8
How can I write SUMIF on the conditions on, add total cats for the month of March?
I have been trying to experiment with SUMIF and written something like:
=SUMIF(A:A,Cat,D:D)
This is only going to work on one dimensional, meaning colum. How do I write a formula to calculate the sum of total cats in March? Column+ March , two dimensional.
You may try this:
=SUMIF(A1:A4;"Cat";INDEX(B1:D4; 0; 3))
The value of 3 in INDEX function means the third column (March), you may change it into 2 for February, and change it into 1 for January

Categorizing data in Excel using formula

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

cognos: Pick up the initial value for every row of a crosstab

I have a requirement in which i have to pick up the initial value of each row in a crosstab..
My crosstab looks like this
value 1960 1970 2010 2011
aus 10 5 11 6
eng 5 2
bra 11 4
ind 8 11
i have to add another column which picks up the initial value for every row based on the year..
so the result should look like this.
value 1960 1970 2010 2011 initialValue
aus 10 5 11 6 10
eng 5 2 5
bra 11 4 11
ind 8 11 8
You should be able to use the minimum() function to determine the lowest value for year and then return the value corresponding to that. The expression for the initialValue data item would be something like:
total(
CASE
WHEN [Year] = minimum([Year] for [Language])
THEN [Value]
ELSE 0
END
for [Language])
We get the lowest year for the specific language in the data set using the minimum() function using the for clause to define the aggregation level. If the year of the row matches this number, we output the value, otherwise we output 0. We then total everything up for each language which should give us the value for the lowest year.
This solution assumes that the numbers displayed in your crosstab are totals of lower-level row detail. If the aggregate is something different, such as average or count, the wrapping summary function should be changed accordingly.

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