Getting the max of a column based on criteria in another column - excel

I have some data like:
Group
Alpha
Numeric (Sometimes)
1
A
Z
1
B
X
1
C
Y
2
B
Z
2
A
X
2
C
Y
A, B, and C repeat in that not necessarily in that pattern but always in groups together, while the numeric column is often numeric data that varies or text. How can I get the max numeric value for a group for just A and B using a repeatable formula (or a lambda function)? I have tried using vlookup for A and B in the range composing a group and passing the numeric column to MAX() but when the numeric column has text, MAX() and MIN() fail (even though it supposedly ignores text). Any ideas on how to get it to return correctly?

Related

How to recursively calculate mean of values based on values present in another cell of the same row in Excel

I have a spreadsheet with two columns of values, containing 1000 values each. The first column (column A) contains these values:
W
W
W
T
T
T
The second column (column B) contains these values:
1
2
3
4
5
6
Here is an image of the spreadsheet:
Can you please tell me if there is a way to recursively calculate the mean of those values in column B that have the same value in column A? In my case, the output should be a new column that looks like this:
2
5
As you can see, "2" is the mean of values in column B that has "W" in column A, while "5" is the mean of values in column B that has "T" in column A.
This type of question can be handled using the SubTotals feature, using Average() as the function to be used (instead of the default Sum() function).

Sum rows containing only the first appearance of value in separate column

I have a table that looks something like this:
Column A | Column B
A 1
B 2
C 3
A 4
What I want to do is get the sum of the values in Column B, but only first the first occurrence of each value in Column A. Thus, the result I want to get is (1 + 2 + 3) = 6 (Adding the first three rows, but omitting the fourth, because a row with 'A' in Column A has already included in the sum).
I've tried looking at Frequency, but I haven't been able to figure out how to use it properly to get the result I want.
Use SUMPRODUCT and MATCH:
=SUMPRODUCT(--(ROW(A1:A4)=MATCH(A1:A4,A:A,0)),B1:B4)

EXCEL: count combinations for unique values

I'm trying to count the following in excel:
I have a number of unique values for X (say 4), each appearing twice (in random order) in the data set. I want to count the number of each combination (regardless of order) of values on a second column Y for each value of X.
Example (here in order):
X Y
1 A
1 D
2 A
2 C
3 B
3 C
4 A
4 D
As output, I need:
n A,D 2
n A,C 1
n B,C 1
n B,D 0
(Let's assume all other combinations don't exist.)
Is this possible without rearranging the data? I don't mind putting in 4 formulas (for each possible combination).
My starting point was akin to this: excel count unique combinations of columns, but I can't quite figure it out and also I know what feels like next to nothing about excel or coding...
To get the count of pairs if the data is not in order, first one needs to get the pairs by X. Create a unique list of X and use this formula:
=CHAR(AGGREGATE(15,6,CODE($B$2:$B$9)/($A$2:$A$9=D2),1))&","&CHAR(AGGREGATE(15,6,CODE($B$2:$B$9)/($A$2:$A$9=D2),2))
Note this only works if the Y is one character like your data.
Then create a unique list of that output and use a standard COUNTIF:
=COUNTIF(E:E,G2)
Or you can use a pivot table on the first helper columns to get the same without the need of getting the unique pairings.
If you use a helper column, you can combine the data into something you can count. Use the formula =IF(A2<>A1,B2,C1&","&B2) in column C. So your data then becomes:
X Y
1 A A
1 D A,D
2 A A
2 C A,C
3 B B
3 C B,C
4 A A
4 D A,D
Then it's a matter of counting up the combinations. Here's a snapshot of my example:
You can use the MMULT function for this purpose, like this (You can insert line breaks with Alt+Enter but you do not have to, it also works if you write it on the same line):
=SUMPRODUCT(
--($B$2:$B$19= LEFT($D2,FIND(",",$D2)-1) ),
MMULT(
--($A$2:$A$19=TRANSPOSE($A$2:$A$19)),
--($B$2:$B$19= MID($D2,FIND(",",$D2)+1,LEN($D2)) )))
You have to enter this as an array formula (After typing, press Ctrl+Shift+Enter, instead of just Enter; you will see the formula inside braces, like this: {=...}).
Here is a screenshot to show what the ranges in the formula mean:

Excel: Count of reciprocal pairs in two columns

I have two columns that each contain pairs of individuals.
Individual 1 Individual 2
A B
A C
A D
B A
C A
C D
How would I create a count of the number of times an individual has a reciprocal pair i.e. matched with the same partner but in the opposite order? For this example, the output should be:
A: 2
B: 1
C: 1
D: 0
I think this is quite tricky but here are two suggestions
=SUMPRODUCT(COUNTIFS(A$2:A$7,B$2:B$7,B$2:B$7,A$2:A$7,A$2:A$7,C2))
or
=SUM(((A$2:A$7&B$2:B$7)=TRANSPOSE(B$2:B$7&A$2:A$7))*(A$2:A$7=C2))
The second one has to be entered as an array formula using CtrlShiftEnter and I'm assuming that the A's and B's are in A2:A7 and B2:B7 and you can get a list of the four individuals A, B, C and D in C2:C5.

Sum column X based on value in column Y not being in array Z

To keep things simple I have 3 columns (place holders used)
X - Contains Revenue
Y - Contains a number (hotel room number)
Z - Independent list of numbers (room numbers belonging to a certain category)
I'm trying to tally all the revenue in column X for rooms that do not appear in Column Z. Here is my attempt:
=SUMIFS(X2:X2000,Y2:Y2000,"<>"&Z2:Z198)
But that is still totaling all the revenue without the conditional. Pointers?
Try it with a SUMPRODUCT function.
As a standard formula,
=SUMPRODUCT(X2:X2000, --ISERROR(MATCH(Y2:Y2000, Z2:Z198, 0)))
Keep column X and column Y references limited to the actual data but the same size. Column Z should likewise be limited but does not necessarily have to be hte same size. Do not use full column references.

Resources