Average based on criteria then output - excel

I have an Excel table with the first six columns having a value of 1 or 2. The next six columns are associated with the first six columns and have values that will need to be averaged - two averages will be computed based on whether there is a 1 or 2 value in the first six columns. Then depending on the two averages, the last six columns will need to be assigned a value equal to H (high average) or L (low average). This is difficult to explain, so here is an example:
A B C D E F G H I J K L M N O P Q R
1 2 2 1 2 2 1 8 8 9 8 6 8 L L H L L H
Columns C and F have values equal to 1, so columns I and L need to be averaged. Then because columns A, B, D and E have values equal to 2, columns G, H, J and K need to be averaged. The average of the columns associated with a value of 1 (I and L) is 8.5, and the average of the columns associated with a value of 2 (G, H, J and K) is 7.5. Columns M-R now must be labeled with an H or L depending on whether the corresponding values from columns G-L were part of the high (H) or low (L) average. In this case, since columns I and L had the larger average, then columns O and R need to be assigned an H. The other columns (M, N, P and Q) will be assigned an L because their associated columns (G, H, J, K) had the lower average.

Please consider the following formula placed on the first row of Column M and then copied across to Column R:
=IF(AVERAGEIF($A$1:$F$1,A1,$G$1:$L$1)=MAX(AVERAGEIF($A$1:$F$1,1,$G$1:$L$1),AVERAGEIF($A$1:$F$1,2,$G$1:$L$1)),"H","L")
Logic is if the average of the values that correspond to either the 1 or 2 on A1 is equal to the MAX of calculations between both, then this corresponds to the High number. If not it corresponds to the Low value. Note that this does not consider for when the averages are equal in which case all entries are noted as High. You can extend this by adding to the formula to check if the value is equal to the MIN of the same. Hope this helps. Regards,

If you don't want to use Visual Basic, you could use this method, but it might require more columns.
xx A B C D E F G H I J K L
1 2 2 1 2 2 1 8 8 9 8 6 8
For cell M1 type in: =if(A1=1, G1, "")
Note that this is two regular quotes (")s in a row after the G1 term.
Copy this over to cells M1-R1.
Now cells M1-R1 should only contain data for columns marked with a 1.
Next for cell S1 type in: =average(M1:R1)
This shouldn't factor in blank cells, So you should just have the average of "1" cells.
Now copy the process for the "2" cells:
For cell T1 type in: =if(A1=2, G1, "")
Copy this to cells T1-Y1.
For cell Z1 type in: =average(T1:Y1)
Now for cell AA1 type in: =if(S1 > Z1, 1, 2)
Now AA1 will have the number that has the higher average. So if the "1" cells had a higher average, cell AA1 will be a 1, otherwise it will be a 2.
Now for cell AB1 type in =if(A1=$AA1, "H", "L")
Copy AB1 to cells AB1 through AG1 and you're done.
Cells AB1-AG1 will have your H's and L's. Note that there is one drawback to this method, apart from it being a little complex, that is that if the averages are equal, it will still print "2"s as having the higher average.
Anyways hopefully you can find a simpler method, but this one should work if you can't.

Related

Return Multiple Unique Matches in Excel without Array Formula

Given an Excel table of shape
Col. A Col B Col. C Col. D Col. E
x 2 x 2 3
x 3 y 7
y 7 z -5
x 2
z -5
I want to return the first unique hit in Column B for argument "x" in Column D,
the second unique hit in Column B for argument "x" in Column E and so forth.
The formula I'm currently using in cell D1 for this is
{=IFERROR(INDEX($B$1:$B$5,MATCH(0,COUNTIF($C1:C1,$B$1:$B$5)+($A$1:$A$5<>$C1),0)),"")}
which is working.
The problem I'm having is that since this is an array formula and since I'm analyzing a decent amount of data computation time for my sheet is too high.
Is there an alternative for this functionality avoiding an array formula?
Thanks!
Haven't got time to test this properly, but if you have Excel 365 you can use a single formula per row and it may be faster:
=TRANSPOSE(UNIQUE(FILTER(B1:B10,A1:A10=C1)))
in D1.
EDIT
To pull the formula down, you need static references as OP has pointed out. Probably should check for empty cells in column C as well, so formula becomes:
=IF(C1="","",TRANSPOSE(UNIQUE(FILTER(B$1:B$10,A$1:A$10=C1))))

Deducting numbers based on value in a different column

I have a C column with several rows containing numbers. I have another E Column with rankings.
I would like a formula that will automatically change the number in a 3rd column G based on the ranking in E column
So,
If the ranking is 2 in E the number in G is number in column C
minus 1
If the ranking is 1 the number in E the number in G is
number in column C minus 2
Any other ranking the number remains the
same.
Example -
C E G
19 2 18
12 1 10
15 3 15
Put below formula in G column -
=IF(E1=1,C1-2,IF(E1=2,C1-1,C1))
Above formula is for row 1. Adjust row value according to your need.
Explanation -
Check if E column contains 1, then subtract 2 from C column
Else, check if E column contains 2, then subtract 1 from C
column
Else, G column is same as C column

Change column width based on another cell value

In excel, I have two three columns and after transpose I have some change to make. Let the data be ::
A B C
a K .2
a Q .23
a R .45
b L .3
b S .12
c M .43
d N .54
e O .32
f P .067
After transpose::
a K Q R
b L S
c M
d N
e O
f P
Each row is filled by whatever values I have in column B corresponding to column A. Now the problem is the cell in which I fill K L S Q R i.e. column B values should be of different sized and in ratio of their weight which is column C.For example K should be 0.2, R should be 0.45 or in the same ratio. And since these are written one below the top entire column could not be changed for "a" since the next row cells would be again of different sizes each.
I think this could be achievable by macro but I am not sure about that.Please let me know if you need any further information. Thanks!
Not exactly sure what you mean from your wording but it is certainly easy to change column width via vba.
If you want to change column F based on value of C3 then you need:
Range("F:F").ColumnWidth = Range("C3").Value
Obviously qualify your range so it's specific to whatever sheet / workbook you want etc.

Keep on summing corresponding cell and compare with first column for summing up first column based on comparision in excel

Consider the following data setup:
_A_ _B_ _C_
1 1
2 1 1
3 3
Such that a formula would return the following results for columns B and C respectively:
_A_ _B_ _C_
4 2
Now I want to sum column A if A-(B+C) is equal to 0.
so for above example sum would be 1+3 = 4 on column B, since row 1 and 3 satisfy 1-1=0 first row, 3-3=0 third row. so A value on 1st and 2nd row is 1+3=4. Row 2nd doesn't satisfy 2-1=1 not 0 so ignore.
on column C, B+C in second row 2-(1+1) = 0 ,So it would be sum 2 in that column C, ignoring first and third row since it already has been counted on column B.
columns continue like D E....
So sum up from B to current column..so if i am in column B it will sum up till B.If in C B+C....If in D B+C+D etc and then compare with column A
Insufficient rep to comment, this is at least a partial answer and perhaps full.
I think you're looking for this to happen in some lower row in B:
=SUMPRODUCT(--(A1:A3=B1:B3),A1:A3)
And this in C:
=SUMPRODUCT(--(A1:A3-(B1:B3+C1:C3)=0),A1:A3)
Although as EEM points out all the sample rows satisfy this condition so you get "6" instead of "2"

Excel get average of a result of index+match function, see details

So I have:
A B C down here i want to get an average
like this:
v 1 a (*1) filter col "C" for what i have in row for col C, in this case "a", then filter col A for what I have in my row for col A, then all those rows must be counted, then sum them and then: sum/count
v 2 a
y 3 a
y 7 a
y 3 a
v 2 b
y 4 b
v 2 b
y 7 b
thanks
You want COUNTIFS and SUMIFS (check Excel help for the params)
Assuming your first row starts on A1:
=SUMIFS($B$1:$B$9,$C$1:$C$9,C1,$A$1:$A$9,A1) / COUNTIFS($C$1:$C$9,C1,$A$1:$A$9,A1)

Resources