excel average if-function advanced - excel

I am trying to get the average value(s) of some specific entries. I have two columns: A-which is an index column (it goes e.g. from 1 to 1000) and B which is the values column.
I know there is an AVERAGE function and there is an AVERAGE IF function, which will probably help me but I can't seem to get it working the way I need to.
What I need to do is to get the average value of the entries in column B that match this description for the index in column A: 3 + (3*n) in which n >= 0. In this case I need the average of the values in column B, whose entries in A are 3, 6, 9, 12, 15...
Is it possible to do this with excel or do you think it would be better to write a program to get those values?
Thanks for your tips!!
-Jordi

You can use an "array formula" with AVERAGE function, e.g.
=AVERAGE(IF(MOD(A2:A100,3)=0,IF(A2:A100>0,B2:B100)))
confirmed with CTRL+SHIFT+ENTER
To modify according to your comments in simoco's answer you can use this version
=AVERAGE(IF(MOD(A2:A100-11,3)=0,IF(A2:A100-11>=0,B2:B100)))
That will average for 11, 14, 17, 20 etc.

You can use SUMPRODUCT for this:
=SUMPRODUCT((MOD(A1:A1000,3)=0)*B1:B1000)/MAX(1,SUMPRODUCT(1*(MOD(A1:A1000,3)=0)))
Explanation:
MOD(A1,3) gives you 0 only if value in A1 is in form 3*n
MOD(A1:A1000,3)=0 gives you array of true/false values {FALSE,FALSE,TRUE,FALSE,..}
since False is casts to 0 and TRUE casts to 1 when multipliybg by any value, (MOD(A1:A1000,3)=0)*B1:B1000 returns you array of values in column B where corresponding value in column A is in form 3*n (otherwise zero 0): {0,0,12,0,..}
SUMPRODUCT((MOD(A1:A1000,3)=0)*B1:B1000) gives you a sum of thouse values in column B
SUMPRODUCT(1*(MOD(A1:A1000,3)=0)) gives you number of values in form 3*n in column A
and the last thing: MAX(1,SUMPRODUCT(1*(MOD(A1:A1000,3)=0))) prevent you from #DIV/0! error in case when there is no values in column A in form 3*n
UPD:
in general case, say for rule 11+3*n you could use MOD(A1:A1000-11,3)=0

Related

Excel Vlookup function to map duplicate and get the max occurence value

Here Table A has values where A,C has duplicate. In Table B , for each of A,B,C which is considered as input to table A , it should fetch 12,33,14. The table b populates the output by checking the occurrence in Table A and getting the most common value . Here in this example A had 11 & 12. But 12 had 3 occurence.so it's value is 12 Table B can have other values like D or can miss EITHER A OR B OR C. is there any Excel function through this i can achive. I know if u put count and the sort based on count it will work. I am looking for 1 line function
something like Vlookup in excel
Assuming no Excel version constraint per tag listed in the question. You can try the following in cell D2:
=LET(A, A2:A8, B, B2:B8, cnts, COUNTIFS(A,A,B,B), ux, UNIQUE(A),
out, MAP(ux, LAMBDA(x, TEXTJOIN(",",,UNIQUE(FILTER(B, (A=x)
* (cnts = MAX(FILTER(cnts, A=x)))))))), HSTACK(ux, out))
The formula considers the scenario where one or more values have the maximum number of occurrences, like in the case of C value, both values 13, and 14 are present in just once. We use TEXTJOIN to collect both values.
Here is the output:
Note: You cannot use inside MAP the MAXIFS function because it is a RACON function and cnts is not a range. We use as a workaround MAX filtering by rows that match A=x. The approach of using: MAX((A=x) * cnts) also works, but under the assumption that all filtered values are not negative.

Two-way lookup to return value or next closest value in Excel

I have a three-column table in Excel, called Table1, like this:
Given two values (one for each input variable), one which must be exactly equal to any of the numbers in the first column (2, 4, 6, or 8) and which must be typed in cell F2, and another one which can be any number between the least (1) and greatest (25) numbers in the second column and which must be typed in cell F3, I want to find the corresponding value in the third column. If the value typed for the second variable is not present in the second column of the table, then the output value of the next row is chosen.
For example, suppose the lookup values are 4 (for the first column) and 10 (for the second column), then the output should be E, since both 4 and 10 are present in the first and second columns, respectively, and the row with the output E corresponds to those values for the inputs.
Another example. Suppose the lookup values are 8 (for the first column) and 17 (for the second column), then the output should be K; it is not J because the latter corresponds to a value of 15 for the second column, which is strictly less than 17; so the output is K because it corresponds to the value that is immediately after (or greater than) 17, being 20.
My attempt
To limit the available values the user can choose, I could create data-validated cells. For choosing the values in the first column, the data validation would by of type list and be equal to 2, 4, 6, 8; such cell would be F2. Like this:
For choosing the values in the second column, the data validation would be of the type whole number, with minimum value of 1 and maximum value of 25. Like this:
Now the formulas for the lookup. After googling, I found out that performing a look-up task with two input criteria is known as a two-way lookup. Using the INDEX and MATCH functions, I managed to perform the two-way lookup, unfortunately the formula only allows exact matches, so it works fine when the first and second input values are 4 and 10, but not when they're 8 and 17. The formula is the following, and it is in cell F4:
{=INDEX(Table1[Output], MATCH($F$2 & "|" & $F$3, Table1[1st input variable] & "|" & Table1[2nd input variable], 0))}
(The presence of curly braces means that we must enter the formula with Ctrl + Shift + Enter instead of just Enter.)
Here's a screenshot for the first successful example:
Here's a screenshot for the second failed example:
I tried changing the third parameter of the MATCH function from 0 to 1, but it returns J (which corresponds to 15 in the second column, but 17 < 15) instead of K (which corresponds to 20, since 17 > 20 and 20 is the closest value to 17 that is immediately after it.)
How can I achieve what I want?
if you have Excel 365 then you can use the new Filter-function:
=INDEX(FILTER(Table1[output],(Table1[1st Input variable]=first)*(Table1[2nd input variable]>=second),"no result"),1)
I named F3 "first" and F4 "second".
FILTER returns all output values where
column A = value from F3
column B >= the value from F4.
INDEX selects the first row of the FILTER-result
Not the best way, but you can round the second input to what you need. In your example, all your values are multiples of 5. Just create an exception for number 1 with an IF.
Here's what I tried:
={INDEX($C$1:$C$12;MATCH(F7&IF(ROUNDUP(G7/5;0)=1;1;ROUNDUP(G7/5;0)*5);$A$1:$A$12&$B$1:$B$12;0))}
Notice it's an array formula.

Automatically fill a column based on some criteria from other columns

I would be very grateful if someone could help me with this question.
I'm working on a worksheet which has 3 columns R, SF and DF where the performance percentages
of each of these variables are recorded (R, SF, DF).
If the percentage is greater than 90, the variable is classified as Critical. If the percentage is greater than or equal to 80 and less than 90, the variable is classified as Attention.
Finally, if the variable is greater than or equal to 60 and less than 80, the variable is classified as Trigger.
I would like to automatically fill another column by comparing the 3 percentages of each variable and taking the highest value. If the highest value is the variable R, for example, then the cell in this other column will be filled with R and its respective classification,
(C -Critical or A - Attention or T - Trigger).
Non-VBA Solution
Consider two formulas:
=SWITCH(MATCH(MAX(B2:D2),B2:D2,0), 1, "R", 2, "SF", 3, "DF")
IF(MAX(B2:D2)>=90,"C",IF(MAX(B2:D2)>=80,"A",IF(MAX(B2:D2)>=60,"T","")))
The first formula will provide you with the column index (based on the input range) that is associated with the MAX value. You can then use SWITCH to convert the index - in this instance, we convert to a string. The conversion is as follows:
Column Index:Output = 1:R, 2:SF, 3:DF
The second formula is nested IF statements which gets evaluated from left to right. Once your criteria is met, the rest of the formula will not be evaluated so you only need to check for Greater Than criteria rather checking for In Between as you explained.
If you want the output in one cell you can just combine the formulas with & as shown below. I have also shared a photo of the setup I used so you can relate the formula to the ranges
A2 = SWITCH(MATCH(MAX(B2:D2),B2:D2,0), 1, "R", 2, "SF", 3, "DF") & IF(MAX(B2:D2)>=90,"C",IF(MAX(B2:D2)>=80,"A",IF(MAX(B2:D2)>=60,"T","")))

Excel IF function greater than x but less than y

I'm trying to arrange a column so that I can essentially "score" results.. I am looking for a formula that will go "If greater than 100000 but less than 110000 = 10, if greater than 90000 but less than 99999 = 9, etc etc.. can someone help?
We can use LOOKUP with ranges:
=LOOKUP(A2,{0,90000,100000,110000,120000},{"0-89999","90000-99999","100000-109999","110000-119999","120000-Inf"})
I used lookup output as ranges to show what lookup is trying to do, in your case use below:
=LOOKUP(A2,{0,90000,100000,110000,120000},{8,9,10,11,12})
You can do this a few ways. Vlookup or summing if statements. Assuming your column you want to score is in column A and you are scoring in column B try these:
Vlookup
(assuming a table is on column c and d)
=VLOOKUP(A1,C1:D2,2)
Ifs
=IF(A1=10000,10,0)+IF(A1=9000,9,0)

variable cumulative target point without new row OR without VBA

What I need to do is (please refer to the image below):
red numbers in C column should be calculated by excel. I wrote the
values that must be calculated after the proper formula is applied.
Each red number in C column gives the 1st point that the total of the values between D & I columns are >= related confidence level. For example:
C2 value is 2 because D2+E2+F2>=0,85. Since F2 is the 1st point to satisfy this requirement, C2 value is 2 (value of F1)
another example; C3 is 0 since immediately D3>=B3 already.
It won't be a proper solution to use only IF() function (that is what I can do but not proper) because this image is a simplified version of my real case. In my real case columns that are 0, 1, 2, 3, 4, 5 are extended until 60.
Is there any solution to this case
without VBA
without creating new rows for calculating cumulative values (there are also tons of reference rows so new rows will create fill-down inefficiencies)
regards
A simpler solution would be to add new columns to the right of your existing columns, and use those for cumulative values: then there's no problem with fill-down.

Resources