How sum in excel only for given value - excel

I have in excel something like:
A B
1 Value1 10
2 Value2 20
3 Value1 5
4 Value1 10
5 Value2 15
How I can sum for given value in A? For example, having something like this:
6 C D
7 Value1 25 (sum of b1+b3+b4)
8 Value2 35 (sum of b2+b5)
Of course, how can I do this automatically and not manually.
Thanks very much.

Let's assume you have a list of the unique values in column A listed in column C, i.e.:
Row A B C
1 Value1 10 Value1
2 Value2 20 Value2
3 Value1 5
4 Value1 10
5 Value2 15
In column D, the following formula will count the occurences of each value in column C:
=SUMIF(A$2:A$6, "=" & $C2, B$2:B$6)
This should be pasted into D2 and then copied to D3, D4, etc.
The result will look like:
Row A B C D
1 Value1 10 Value1 25
2 Value2 20 Value2 35
3 Value1 5
4 Value1 10
5 Value2 15
How does this work? SUMIF allows criteria to be used, and if satisfied, a SUM of the cells is taken. In this case, the SUMIF does this:
Looks in cell range A$2:A$6
Compares the value in each cell to see if it is equal to $C2 (or $C3, etc dependent upon which row is being calculated)
If it is equal, sum the value from the cell range B$2:B$6
Limitations
In order for this to work, the unique values in column A must already be known and listed in column C. There are some ways of generating a list of unique values but they are not straight-forward. Roll on UNIQUE which ships with the new version of Office.

There are different ways to do this:
Use a pivot table (as already mentioned in the comments).
Use a SumIf() worksheet function (as mentioned in another answer). This, however, will only work if you know all names (like Value1, Value2, ... (the list MUST be limited))
Use subtotals. This, however, will only work when you sort first.
Write a VBA macro.

Related

How to find the maximum of lookup values in excel

I have an excel table that looks like this
Row Column1 Column2 Column3
R1 A B C
R2 C D X
I have a table that holds the values corresponding to the entries in Columns 1 to 3 which looks like this -
Key Value
A 1
B 7
C 2
D 4
X 9
I want to create a Column4 that has the maximum looked-up value of columns 1 to 3, i.e. the result would look like this -
Row Column1 Column2 Column3 Looked_Up_Max
R1 A B C 7
R2 C D X 9
I tried writing an array formula like this -
={max(if(B1:D1,vlookup(B1:D1,lookup_table!$A$1:$B$5,2,0)))}
But it does not work. Any way to do this is one step instead of say creating three additional columns with the looked up values and then taking a max of the additional columns?
Thank you for the help
If the data on the lookup table is sorted then you can use this array formula:
=MAX(LOOKUP(B2:D2,$H$2:$H$5,$I$2:$I$5))
Being an array it needs to be confirmed with Ctrl-Shift-enter instead of Enter when exiting edit mode.
Another that does not care about sort order that uses SUMIFS()
=MAX(SUMIFS(I:I,H:H,B2:D2))
Still an array formula, but this assumes that the Key in the lookup is unique.
If not in order and not unique and the user wants the first then we need this convoluted array formula:
=MAX(IFERROR(INDEX(I:I,N(IF({1},MATCH(B2:D2,H:H,0)))),-1E+99))
Still and Array formula.

Copy/Move cells by id

How can I move values from Worksheet 1 column B to Worksheet 2 column B, based on a unique ID in column A? Some IDs are duplicates and some values are empty, I would like to ignore empty values.
Worksheet 1:
A B
23452 value1
23452
53252 value2
67452 value3
Worksheet 2:
A B
53252
23452
67452
Wanted Result (Worksheet 2):
A B
53252 value2
23452 value1
67452 value3
What I have tried
Merging data in Open/Libreoffice calc - could not figure this out for my specific requirements.
You can try this simple INDEX-MATCH formula,
In column B of sheet2,
=INDEX('Sheet1'.A:B;MATCH(A1;'Sheet1'.A:A;0);2)

Counting unique list of items from range based on criteria from other ranges

I have a file with data in the following format:
text value1 value2
Given value 1 and value 2 meet some criteria, find all the unique text values.
The exact data looks like this:
john 10 20
john 15 35
mark 20 10
mark 25 15
tom 25 40
lee 16 50
If val 1 <=25 and value 2 <=35 the number of unique text = 2 (john and mark)
I have to do this using formulas not filters.
I've been trying combinations of frequency, countifs, sumproducts and a whole range of other methods and can't seem to hit what I'm looking for.
Assuming that text, value1, and value2 are in columns A, B, and C respectively ...
In D1, enter the formula =IF(AND(B1<=25,C1<=35),A1,"") and copy it down the column
Use the formula =SUMPRODUCT((D:D<>"")/COUNTIF(D:D,D:D&"")) for your answer
If you want to list the unique values rather than count them, something like this:-
=IFERROR(INDEX(A$2:A$7,MATCH(0,IF((B$2:B$7>25)+(C$2:C$7>35),1,COUNTIF(E$1:E2,A$2:A$7)),0)),"")
entered as an array formula starting in E2 ( and assuming that you are using columns A,B and C for your data.
See this reference for explanation.
The following formula will do what you are asking:
=SUM(IF(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""),IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""))>0,1))
This is an array formula so confirm it with Ctrl-Shift-Enter.
I referred to this webpage.
Also found a shorter one:
=SUM(--(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,COUNTIF(A2:A7,"<"&A2:A7),""),""),COUNTIF(A2:A7,"<"&A2:A7))>0))
Found and modified from hre.

Find duplicate rows in Excel table and sum rows

I have an Excel table whose unique key is the combination of Para1, Para2 and Para3:
Para1 Para2 Para3 Value1 Value2 Value3
A B C 1 2 3
A E F 4 6 4
A B C 5 3 7
P Q R 4 2 4
I want to find the duplicates and SUM the values, so the expected output is:
Para1 Para2 Para3 Value1 Value2 Value3
A B C 6 5 10
A E F 4 6 4
P Q R 4 2 4
Is there a way to group the data get the SUM?
You could copy the columns 1,2 & 3. Then remove the duplicates and put a SUMIFS function in the Value columns.
Assuming Para1 is in A1, insert a column on the left that concatenates the key elements:
=B1&C1&D1
and copy down to suit. Sort your data by that column and apply Subtotal At each change in: Para1Para2Para3, Use function: Sum, Add subtotal to: check Value1, Value2, Value3, Replace current subtotals and Summary below data, OK.
Filter ColumnA, Text Filters, Contains..., tot, OK. In B4 enter:
=B3
copy across to D4 and B4:D4 down to suit. (Select All) in ColumnA, select all cells, Copy, Paste Special..., Values, OK over the top. Filter ColumnA again to select Does Not Contain..., tot, OK and delete all visible except the labels. Delete ColumnA and last row. Select all cells and in Subtotal select Remove All.

EXCEL match 2 columns against each other

I have two columns of data, they look something like this:
A B C D
1 2 SOME RECORD
2 6 SOME RECORD
3 10 SOME RECORD
4
5
6
7
8
9
10
So basically column A is a list of indices, where some of them appear in column C with corresponding records saved in column D. Column B is currently empty, and what I want to do is if say index 2 appears in both column A and column C (they matches), then put the record beside C2 in the cell B2. So essentially I want it to look like this:
A B C D
1 2 SOME RECORD
2 SOME RECORD 6 SOME RECORD
3 10 SOME RECORD
4
5
6 SOME RECORD
7
8
9
10 SOME RECORD
Can someone help please?!! Thanks!!!
UPDATE: I tried this and it doesn't work. The data in column D is calculated using a UDF and is refreshing every 1 second. The VLOOKUP function fails even though I can see the 2 indices are the same!! Is it because of the format of the cell or column? I.e. does vlookup compare data type as well?
Assuming your data in A starts from A1 - put in B1 the following and autofill:
=IFERROR(VLOOKUP($A1,$C:$D,2,0),"")
This includes handling of missing values.
You'll want this:
B1=VLOOKUP(A1, C:D, 2, FALSE)
This will look up the value in column A within the array spanning columns C and D. It will give you the value found in the second column (D). FALSE makes it an exact match, otherwise you might get 2 and 20 matching because hey, they're kind of similar...

Resources