SUM of multiple VLOOKUP - excel

It seems like a simple problem, but I do not manage to solve it. I have the following tables:
Values
| Key | Value |
|-----|-------|
| A | 1 |
| B | 2 |
| C | 3 |
Results
| Foo | Bar |
|-----|-----|
| A | B |
| C | B |
| A | A |
| B | C |
| ... | ... |
What I am looking for is a final row in the Results table that looks for the key in the Values table, takes its value and sums all the keys in a column (i.e. FOO and BAR). The final result would be:
| Foo | Bar |
|-----|-----|
| A | B |
| C | B |
| A | A |
| B | C |
|-----|-----|
| 7 | 8 |
I have been trying with different VLOOKUP, INDEX and MATCH functions, but still I am not able. Any ideas?

I asume you want a solution without extra columns. Then you are into Array formulas (a.k.a CSE or ControlShiftEnter functions).
Combination of {=SUM(VLOOKUP(...))} doesn't work, but combination of {=SUM(SUMIF(...))} does:
in A12 enter =SUM(SUMIF($A$1:$A$3;A7:A10;$B$1:$B$3)) and save with Ctrl+Shift+Enter. You then can copy this to B12.
Problem is you will need to change the Array function every time you add values to the list A7:B10 (or you initially make the range sufficiently large) ... this would speak more for extra =VLOOKUP() columns as suggested by CustomX.

I'm not sure of other solutions, but you could solve this by using an extra 2 columns, E and F for example.
Enter this in column E: =VLOOKUP(C2;$A$1:$B$3;2;0)
Enter this in column F: =VLOOKUP(D2;$A$1:$B$3;2;0)
Pull the formulas down and add a SUM at the bottom of column C and D to calculate columns E and F.
Extra: These are the columns I used for your examples.
Key = column A
Value = column B
Foo = column C
Bar = column D

Related

Is there a way to automate populating cells with the names of the column depending on whether the row has values?

I'm tasked with populating cells in excel with values that are names of the columns. For example here's the type of table I'm trying to accomplish. I need to populating the values of column A with the names of the columns that have values (an "x") in that specific row.
+---+-----------+----------+----------+-----------------+
| | A | B | C | D |
+---+-----------+----------+----------+-----------------+
| 1 | | name1 | name2 | name3 |
+---+-----------+----------+----------+-----------------+
| 2 |name2;name4| x | | x |
----+-----------+----------+----------+-----------------+
| 3 |name3;name4| | x | x |
+---+-----------+----------+----------+-----------------+
| 4 |name1;name2| x | x | |
+---+-----------+----------+----------+-----------------+
| 5 | | x | x | x |
+---+-----------+----------+----------+-----------------+
| 6 | | | | |
+---+-----------+----------+----------+-----------------+
For example, A5 should have the value name1;name2;name3, because columns B, C and D have values. A6 should not have anything.
Is there a way to automate this in Excel? Or do I just have to keep doing it manually?
Thank you!
With Office 365 and later:
=TEXTJOIN(";",TRUE,FILTER($B$1:$D$1,B2:D2="x",""))
With Excel 2019:
=TEXTJOIN(";",TRUE,IF(B2:D2="x",$B$1:$D$1,""))
And use Ctrl-Shift-Enter instead of Enter when exiting edit mode.
If one has an older version than those above they can use a UDF in vba. HERE is a UDF that mimics TEXTJOIN. The formula used would be the second one above.

Combining rows of a table using similar cells of one of its columns in Excel

I have a table (1) in Excel, with two columns, in which at the first column (A) there are some numbers and at the second column (B) there are some letters. I want to have a method to make another table (2) from (1) to put different letters at the first column then to put in each row the numbers that were corresponded to letters in table (1).
For example, let the table (1) is:
| A | B |
|---|---|
| 1 | a |
| 1 | b |
| 2 | a |
| 2 | c |
| 3 | b |
| 4 | b |
What is a method in Excel which make the following combination table:
| a | 1 | 2 | |
| b | 1 | 3 | 4 |
| c | 2 | | |
in which letters are in first column and in each row there are the numbers that were in relationship with the row's letter in table (1)?
As per below screenshot use below formula to C1 cell.
=UNIQUE(B1:B6)
And following formula to D2 cell then drag down
=TRANSPOSE(UNIQUE(FILTER($A$1:$A$6,$B$1:$B$6=C1)))

Spreadsheet Formula to Sum Values Over A if B is not in a List of Values

I have a table that looks the following:
| A | B | C |
| 40 | 1 | 1 |
| 180 | 2 | 2 |
| 34 | 1 |
| 2345 | 3 |
| 23 | 1 |
| 1 | 2 |
| 4354 | 3 |
| 2 | 2 |
| 343 | 4 |
| 2 | 2 |
| 45 | 1 |
| 23 | 1 |
| 4556 | 3 |
I want to get the sum of all fields in A where B is neither 1 nor 2 or any other value from colum C. This column contains the values of B where values from A should not be considered for the sum.
I do not know which values B might contain, those values are random and could grow larger, I just wanted to make the example small. My current solution is
{=SUMIF(B1:B13,C1:C2,A1:A13)}
so i can set the lines that should be excluded from the sum in column C. Unfortunately, the current solution does not solve my problem but something different -- it sums up the corresponding entries by value in C. My preferred solution would look something like
=SUMIF(B1:B13,"<>{1, 2}",A1:A13)
=SUMIF(B1:B13,"<>"&C1:C2,A1:A13)
if that were possible (it isn't). I would like to have:
a field (with a list, for example) or column where i can put in the values of B that I do not want to be part of the sum over A.
a method that works with Open Office as well as Excel. I prefer an OO solution.
You could use an array formula so that you can multiply each value in A with a condition. That condition can be any valid Excel formula, so, for instance, you could use MATCH to test if the B value occurs in C:
=SUM((A1:A13)*ISNA(MATCH(B1:B13,$C:$C,0)))
The ISNA function returns TRUE when the match fails, which in a multiplication is used as a numerical value 1. FALSE will make the product 0.
Make sure to enter this as an array formula with Ctrl+Shift+Enter

Excel: get the value of third column on the behalf of second column

i am not much familiar with excel formulas and i am trying to get the value of third column on the behalf of second column.
Example:
|---------------------------------------------------------|
| A B C D E |
|-----|----------|----------|--------------|--------------|
|Sr.No| Bar Code | Cat Id | Org BarCode | Org Category |
|---------------------------------------------------------|
| 1 | 89457898 | | 85214784 | 2 |
| 2 | 87414714 | | 63247458 | 3 |
| 3 | 85214784 | | 89457898 | 4 |
| 4 | 63247458 | | ---- | --- |
-----------------------------------------------------------
i just want to update column C by column E on the behalf of column D and B
can any one please tell me the formula, how i can do this?
Use VLOOKUP. Enter the following formula into cell C1 and then copy it down the C column:
=VLOOKUP(B1, D$1:E$4, 2, FALSE)
To cover more than 4 rows, then just update the formula accordingly. If you want to display a certain placeholder value if a value in column B be not found, then you wrap the call to VLOOKUP as follows:
=IFNA(VLOOKUP(B1, D$1:E$4, 2, FALSE), "Not found")

How to assing a given value randomly in Excel?

I have 30 peoples waiting for result out of 10. I want to assign each of 30 peoples: 7, 8 or 10 result randomly.
Peoples in excel are:
A1:A30
Random numbers in Excel
B1, C1, D1 //Which means B1=8, C1=7 and D1=10
The random number to keep on:
E1 to E30
To get a random integer in a range, use the randbetween(start,end) function. This will produce a random integer between the start and end parameters inclusively. Since your numbers are not contiguous, you can simply index them and perform a lookup using vlookup(randbetween(startindex,endindex),...) to get a random value from the table.
Check out this Example Excel File I created.
Use the following steps to get your desired result:
List the people in column A
Create a lookup table in Columns G and H
containing your desired result values.
In your result column (column E in the example below), add the formula: =vlookup(randbetween(1,3),G:H,2,false)
Column E will now contain either the numbers 7,8,or 10 for each person.
If you want to generalize this and allow any number of different values in your result lookup table, you can change the formula in column E to: =vlookup(randbetween(1,counta(G:G)-1),G:H,2,false).
Note: The -1 is only needed if your lookup table has a header row.
This will select a random value from all non-empty rows in your result lookup table.
In the example below, I added a header row to row 1, and the people start in row 2, for clarity.
+---+---------+---+---+---+--------+---+-----------+--------------+
| | A | B | C | D | E | F | G | H |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 1 | Names | | | | RESULT | | Result ID | RESULT Value |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 2 | Person1 | | | | 7 | | 1 | 7 |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 3 | Person2 | | | | 7 | | 2 | 8 |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 4 | Person3 | | | | 10 | | 3 | 10 |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 5 | Person4 | | | | 8 | | | |
+---+---------+---+---+---+--------+---+-----------+--------------+

Resources