Sum max values in a column based on two other columns - excel

I have three columns and I want the sum of the maximum values in Col2 for each category in Col1 where Col3 is equal to x.
I am not able to add a 4th column to obtain the max first.
Col1 Col2 Col3
a 3 x
b 2 x
c 2 x
a 1 x
b 3 x
c 1 y
a 2 y
b 1 y
c 3 y
In this example the answer I am looking for is 8:
3 for a,
plus 3 for b,
plus 2 for c.
How can I do this?

You could try this with CTRL+SHIFT+ENTER with data in A2:C10 and D1="x":
=SUM(IF(C2:C10=D1,IF(COUNTIFS(A2:A10,A2:A10,B2:B10,">"&B2:B10,C2:C10,D1)=0,B2:B10)))
but note that if there might be more than one max value for a category this sums multiple values. To sum unique max values per category you could try this alternative (also with CSE):
=SUM(IF(C2:C10=D1,(MATCH(A2:A10,IF(COUNTIFS(A2:A10,A2:A10,B2:B10,">"&B2:B10,C2:C10,D1)=0,A2:A10),0)=ROW(A2:A10)-MIN(ROW(A2:A10))+1)*B2:B10))
For example changing the first value from 3 to 1 gives 7 in the first formula and 6 in the second.

Related

sum of column if an other colum matches a value

I have a dataframe, i want to have a new column with the sum of all count where foo is equal than the current row.
It would be possble to create a new dataframe and group sum it there and merge it back. but I guess there is a much simpler solution.
Any hints are highly appreciated
Input:
foo
count
a
3
a
7
b
1
b
2
Output:
foo
count
sum_of_count
a
3
10
a
7
10
b
1
3
b
2
3

turn rows into columns and coping and keeping the same index infrond of all previous together columns

the inverse of
Transpose columns to rows keeping first 3 columns the same
turn:
id col1 col2 col3
1 A B
2 X Y Z
into:
id
1 A
1 B
2 X
2 Y
2 Z
I'm trying unpivot() but from the solution, I cited I need to use .unstack() ?

Transpose Excel Row Data into columns based on Unique Identifier

I have excel table in below format.
Sr. No. Column 1 (X) Column 2(Y) Column 3(Z)
1 X Y Z
2 Y Z
3 Y
4 X Y
5 X
I want to tranpose it in following format in MS Excel.
Sr. No. Value
1 X
1 Y
1 Z
2 Y
2 Z
3 Y
4 X
4 Y
5 X
Actual data contains more than 30 columns which needs to be transposed into 2 columns.
Please guide me.
Select complete table data and then name it as SourceData using
Formula>Name Manager
Now implement following formula for getting first column:
=INDEX(SourceData,CEILING(ROWS($A$1:A1)/(COLUMNS(SourceData)-1),1),1)
And for second column:
=INDEX(SourceData,CEILING(ROWS($A$1:A1)/(COLUMNS(SourceData)-1),1),MOD(ROWS($A$1:A1)-1,COLUMNS(SourceData)-1)+2)
Copy and paste special values and then delete blanks / zeroes.
You will get result as required.
If you were using other databases, there might be a formal unpivot operator/function available. But in MySQL, this is not a possibility. However, one approach which should work here would be to just take a union of the three columns:
SELECT 1 AS sr_no, col1 AS value WHERE col1 IS NOT NULL
UNION ALL
SELECT 2, col2 WHERE col2 IS NOT NULL
UNION ALL
SELECT 3, col3 WHERE col3 IS NOT NULL
ORDER BY sr_no;

Excel Formula comparing two columns

Below is a sample of the data I have. I want to match the data in Column A and B. If column B is not matching column A, I want to add a row and copy the data from Column A to B. For example, "4" is missing in column B, so I want to add a space and add "4" to column B so it will match column A. I have a large set of data, so I am trying to find a different way instead of checking for duplicate values in the two columns and manually adding one row at a time. Thanks!
A B C D
3 3 Y B
4 5 G B
5 6 B G
6 8 P G
7 9 Y P
8 11 G Y
9 12 B Y
10
11
12
11
12
I would move col B,C,D to a separate columns, say E,F,G, then using index matches against col A and col B identify which records are missing.
For col C: =IFERROR(INDEX(F:F,Match(A1,E:E,0)),"N/A")
For col D: =IFERROR(INDEX(G:G,Match(A1,E:E,0)),"N/A")
Following this you can filter for C="N/A" to identify cases where a B value is missing for an A value, and manually edit. Since you want A & B to be matching here col B is unnecessary, final result w/ removing col B and C->B, D->C:
A B C
3 Y B
4 N/A N/A
5 G B
6 B G
7 N/A N/A
Hope this helps!

Count using a category and Median using a category

I have two problems here.
The data is as follows:
Col X Col Y
A 10
A 12
A
A 32
B 11
B 31
B 9
C 8
C 7
C 3
D 1
D 3
D
D 9
I need to do the following:
Count the entries in Column Y using the Categories in Column X, for ex. A repeats 4 times in Column X but has 3 total corresponding numbers in column Y, i need the 3 count of the numbers in Column Y.
Calculate the median of those numbers using the category (excluding blanks whenever there are, not to be assumed as 0 by the code), for ex. Median for A is 12, Median for D will be 3.
Please help.
So 1 is:
=COUNTIFS(X:X,"A",Y:Y,"<>")
2 is:
=MEDIAN(IF(X:X="A",IF(NOT(ISBLANK(Y:Y)),Y:Y)))
Hold down ctrl + shift when you're using 2 as it's an array formula

Resources