How to sum values in excel only if they match a category id in a lookup - excel

Say I have a product category lookup like so:
Sheet 1
Product Name | Product Category
--------------------------------------
product 1 | A
product 2 | A
product 3 | B
product 4 | A
product 5 | B
product 6 | C
and I also have a list of purchases which only use Product Name like this:
Sheet 2
Product Name | Purchase Quantity
---------------------------------------
product 1 | 35
product 4 | 10
product 5 | 5
I would like to produce a rollup like this:
Product Category | Purchase Quantity
------------------------------------------
A | 45
B | 5
C | 0
I've tried a variety of ways to solve this like:
SUMIF(LOOKUP('Sheet 2'!A2:A6,'Sheet 1'!A:A,'Sheet 2'!B:B), "=A", 'Sheet 2'!B2:B6)
SUMPRODUCT(LOOKUP('Sheet 2'!A2:A6, 'Sheet 1'!A:A, 'Sheet 2'!B:B)="A"*'Sheet 2'!B2:B6)
Excel doesn't like the first one. It says the formula is incorrect, but I'm not seeing why. The second one yields #VALUE. Any help on this would be much appreciated. Thanks in advance!

With A in D2, use this as an array formula.
=SUM(SUMIFS(Sheet2!B$2:B$4, Sheet2!A$2:A$4, IF(Sheet1!B$2:B$7=D2, Sheet1!A$2:A$7)))
Array formulas need to be finished with Ctrl+Shift+Enter, not just Enter.

In my opinion there is no need to use complex formulas for such an easy question. Just add another column next to Purchase Quantity sheet 2 to get the Product Category and simply use =SUMIF. I have prepare a solution to illustrate my thoughts:
Formula for VLOOKUP:
=VLOOKUP(D2,$A$2:$B$7,2,FALSE)
Formula for SUMIF:
=SUMIF($F$2:$F$4,"=" & A10,$E$2:$E$4)
Results:

Related

Excel spreadsheet check two conditions along different rows & columns

Hey I'm really stuck on this one, basically tying to get a result of either 'hired' or 'available' (or 0 & 1 to represent) in B2, of BOTH the two conditions in B1 & A2, looking at the log table A6:B10 of when they are 'hired out'. I've tried VLOOKUP and many IF functions but neither quite work correctly.
One option here, though perhaps not the most graceful, would be to use VLOOKUP with the car and date as the key. The issue here is that there are multiple lookup values, namely the car and the particular date. To get around this, you could create a new column C which contains the concatenated car and date, e.g.
A | B | C | D
6 Car 1 | 03-01-2017 | Car 1 03-01-2017 | 0
7 Car 2 | 03-01-2017 | Car 2 03-01-2017 | 0
8 Car 3 | 04-01-2017 | Car 3 04-01-2017 | 0
9 Car 4 | 05-01-2017 | Car 4 05-01-2017 | 0
10 Car 2 | 06-01-2017 | Car 2 06-01-2017 | 0
To create column C, simply enter the following formula into cell C6 and then copy it down the entire column:
=CONCATENATE(A6, " ", B6)
Now you can use the following VLOOKUP formula in cell B2 to calculate whether a given ride is available on a certain date:
=IFERROR(VLOOKUP(A2&" "&B1,C6:D10,2,FALSE), 1)
Here I have hard-coded in column D the value 0 for every entry, to represent that these are rides which are already hired-out for that particular car and date. If our VLOOKUP formula finds a match, then it means the ride is hired-out. If VLOOKUP does not find a match, it would throw an error, in which case we display 1 to indicate availability.

Excel syntax for getting the value in another table based on 2 cells

I would like to know what is the best syntax if i want to get the price of an item depending on the specific product and its unit of measure because a product can be sold per bag or per kilo. Here's a sample content of excel sheet. The only required input for the user is the enter product name and unit of measure in the Orders Sheet.
Orders Sheet
Item Purchased | Unit | Price
-------------------+----------+---------
Product 1 | Bag | 1000
Product 1 | Kilo | 100
~~~~~~~
Price List Sheet
Item | Unit of Measure | Price
----------+---------------------+--------
Product 1 | Bag | 1000
Product 1 | Kilo | 100
Product 2 | Bag | 2000
You can use SUMIFS, which can be used specifically when the result you want is a numeric value:
=SUMIFS(C:C, A:A, E2, B:B, F2)
That's assuming though that your price list is a true price list, meaning no item is duplicated (e.g. Product 1, Bag doesn't appear more than once).

Microsoft Excel Multiple Worksheets and Data

I have two spreadsheets built. I want to be able to put what step a teacher is in which looks like this; BS, 1 or BS, 2 etc. (My second worksheet has each step and salary on it) I then would like the cell directly next to it to pull the correct salary amount from my other Worksheet.
I would add a picture, however it won't let me. Thank you for any help you can offer me.
Assuming the name of the teacher and category of the teacher is in Sheet1 columns A and B
(A) | (B)
|
Max | 1
Tammy | 4
Alex | 2
and on Sheet 2 you have category and salary
(A) | (B)
|
1 | 30000
2 | 45000
3 | 75000
4 | 120000
Then in cell C1 on sheet 1 you would use the formula:
=VLOOKUP($B1,'Sheet2!$A$1:$B$4,2,0)
You would then copy this formula down as required.
Alternatively you could achieve the same results with an INDEX/MATCH combination
=INDEX('Sheet2'!$B$1:$B$4,MATCH(B1,'Sheet2'!$A1:$A$2),0)

How to get two+ rows to link together? Excel 2010 (Example)

I have a parts list with competitor pricing. One part number brings multiple brands up with the location of the company.
As you can see from the picture, I have part numbers for one item with three companies. I want to sort by part type. So for example I want to list only the brake pads. When I do this the blanks get sent to the bottom, but the blanks are not really blanks because they have additional info with them for that part number.
Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | Column 6 | Column 7
Part No | Company A | Price | Company B | Price | Company C | Price
4656546 | Brand A | $5 | Brand A | $5 | Brand A | $5
(BLANK) | Brand b | $8 | Brand b | $8 | Brand b | $8
I have tried to use a helper column, but I have 1,000+ rows.
Does anyone know if you can link or have a relationship between two+ rows?
I hope you understand and if not. I can try to explain better.
I asume that a "blank" in PartNo means "take the PartNo from the cell above" ...
In order to normalize the PartNo (= get rid of the blanks) use another PartNo-Normalized column (e.g. [K:K]) and normalize as following:
K1 ="PartNo-Normalized"
K2:Kxx =IF(A2<>"",A2,K1)
Next convert all formulas in [K:K] into values !!! (Copy / PasteAs - Values) before sorting ... as a sort operation will destroy the calculated values.
After conversion to values it's save to sort, and you may create a filter on that column.
Depending on how well organized your data is, it might be a good idea to add one more column and fill it with 1, 2, 3, 4, 5 ... before any sorting so you can restore the original sort order just in case something nasty happens.

Counting the number of older siblings in an Excel spreadsheet

I have a longitudinal spreadsheet of adolescent growth.
ID | CollectionDate | DOB | MOTHER ID | Sex
1 | 1Aug03 | 3Apr90 | 12 | 1
1 | 4Sept04 | 3Apr90 | 12 | 1
1 | 1Sept05 | 3Apr90 | 12 | 1
2 | 1Aug03 | 21Dec91 | 12 | 0
2 | 4Sept04 | 21Dec91 | 12 | 0
2 | 1Sept05 | 21Dec91 | 12 | 0
3 | 1Aug03 | 30Jan89 | 23 | 0
3 | 4Sept04 | 30Jan89 | 23 | 0
This is a sample of how my data is formatted and some of the variables that I have. As you can see, since it is longitudinal, each individual has multiple measurements. In the actual database there are over 10 measurements per individual and over 250 individuals.
What I am wanting to do is input a value signifying the number of older brothers and older sisters each individual has. That is why I have included the Mother ID (because it represents genetic relatedness) and sex. These new variable columns would just say how many older siblings of each sex each individual has. Is there a formula that I could use to do this quickly?
=COUNTIFS($B:$B,"<>"&$B2,$H:$H,$H2,$AI:$AI,$AI2,$J:$J,"<"&$J2)
Create a column named Distinct with this formula
=1/COUNTIF([ID],[#ID])
Then you can find all the older 0-sexed siblings like this
=SUMPRODUCT(([DOB]>[#DOB])*([MOTHERID]=[#MOTHERID])*([Sex]=0)*([Distinct]))
Note that I made the data a Table and used table notation. If you're not familiar [COLUMNNAME] refers to the whole column and [#COLUMNNAME] refers to the value in that column on the current row. It's similar to saying $A:$A and A2 if you're dealing with column A.
The first formula gives you a value to count that will always result in 1 for a particular ID. So ID=1 has three lines and Distinct will result in .33333 for each line. When you add up the three lines you get 1. This is similar to a SELECT DISTINCT in Sql parlance.
The SUMPRODUCT formula sums [Distinct] for every row where the DOB is greater than the current DOB, the Mother is the same as the current Mother, and the Sex is zero.
I have a possible solution. It involves adding two columns -- One for "# older siblings" and one for "unique?". So here are all the headings I have currently:
A -- ID
B -- CollectionDate
C -- DOB
D -- MOTHER ID
E -- Sex
F -- # older siblings
G -- unique?
In G2, I added the following formula:
=IF(A2=A1,0,1)
And dragged down. As long as the data is sorted by ID, this will only display "1" once for each unique person.
In F2, I added the following formula:
=COUNTIFS(G:G,"=1",D:D,"="&D2,C:C,"<"&C2)
And dragged down. It seemed to work correctly for the sample data you provided.
The stipulations are:
You would need the two columns.
The data would need to be sorted by ID
I hope this helps.
You need a formula like this (for example, for row 2):
=COUNTIFS($A:$A,"<>"&$A2,$E:$E,$E2,$D:$D,$D2,$C:$C,"<"&$C2)
Assuming E:E is column for sex, D:D is column for mother ID and C:C is column for DOB.
Write this formula in H2 cell for example and drag it down.

Resources