How to compare 2 columns in one table with 2 columns in another table?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,533
Office Version
  1. 365
Platform
  1. Windows
I want to create a sheet that I can use to rate soups that I buy and try. I have two tables as shown below. I have included the table names in the top row. They are not displayed by xl2bb.

TblProducts is a list of the products that I have tried. There is one record for each different soup product. There cannot be any duplicates.

TblLog is a list of the tests of these soups. Each soup in TblProducts can be listed zero or more times.

The Ok? column in TblLog tests whether the soup in that row exists in TblProducts. The only way I could think of to make this work is to create the helper column Brand+Flavor in TblProducts. Is there a better way that does not require the helper column?

Mr Excel.xlsx
BCDEFGHI
3Table name: TblProductsTable name: TblLog
4BrandFlavorBrand+FlavorDateOK?BrandFlavor
5Campbell'sChunky Beef with VegetablesCampbell's/Chunky Beef with Vegetables3/04/23OkCampbell'sChunky Beef with Vegetables
6Campbell'sChunky Chicken and Sausage GumboCampbell's/Chunky Chicken and Sausage Gumbo3/07/23OkProgressoChicken Noodle
7Campbell'sChunky Chicken NoodleCampbell's/Chunky Chicken Noodle6/16/23OkCampbell'sChunky Beef with Vegetables
8ProgressoChicken & Homestyle NoodlesProgresso/Chicken & Homestyle Noodles6/23/23OkProgressoChicken Noodle
9ProgressoChicken NoodleProgresso/Chicken Noodle7/04/23OkProgressoChicken Noodle
108/01/23ErrorCampbell'sTomato
119/01/23ErrorProgressoLentil
2-column compare
Cell Formulas
RangeFormula
D5:D9D5=[@Brand] & "/" & [@Flavor]
G5:G11G5=IF(COUNTIFS(TblProducts[Brand+Flavor],[@Brand]&"/"&[@Flavor])=1,"Ok","Error")
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
just a countifs () should work without the helper
countifs( brandrange in tblproducts , brand cell in tbllog , flavour range in tbleprodcuts, flavour cell in tbllog)
copied down
use in an IF , as you have done, to get OK
 
Upvote 0
Solution
just a countifs () should work without the helper
countifs( brandrange in tblproducts , brand cell in tbllog , flavour range in tbleprodcuts, flavour cell in tbllog)
copied down
use in an IF , as you have done, to get OK
I should have tried that. I thought it would test each compare separately. Thank you.

Mr Excel.xlsx
BCDEFGH
3Table name: TblProductsTable name: TblLog
4BrandFlavorDateOk?BrandFlavor
5Campbell'sChunky Beef with Vegetables3/04/23OkCampbell'sChunky Beef with Vegetables
6Campbell'sChunky Chicken and Sausage Gumbo3/07/23OkProgressoChicken Noodle
7Campbell'sChunky Chicken Noodle6/16/23OkCampbell'sChunky Beef with Vegetables
8ProgressoChicken & Homestyle Noodles6/23/23OkProgressoChicken Noodle
9ProgressoChicken Noodle7/04/23OkProgressoChicken Noodle
108/01/23ErrorCampbell'sTomato
119/01/23ErrorProgressoLentil
2-column compare
Cell Formulas
RangeFormula
F5:F11F5=IF(COUNTIFS(TblProducts[Brand],[@Brand],TblProducts[Flavor],[@Flavor])=1,"Ok","Error")
 
Upvote 0
you are welcome
countifs() looks at all the columns to match - its and AND , if you wanted an OR - you can + countifs() together or use an array {}
 
Upvote 0
Thanks for the help. Here's a more elaborate solution.

Mr Excel.xlsx
BCDEFGHIJKLMNO
3Table name: TblProductsTable name: TblLog
4BrandFlavorCountAverage RatingHigh RatingLow RatingFirstLastDateOk?BrandFlavorRating
5Campbell'sChunky Chicken and Sausage Gumbo0n/an/an/an/an/a3/04/23OkCampbell'sChunky Beef with Vegetables75
6ProgressoChicken & Homestyle Noodles195.095.095.010/30/2310/30/233/07/23OkProgressoChicken Noodle85
7Campbell'sChunky Chicken Noodle287.593.082.09/25/2312/29/236/16/23OkCampbell'sChunky Beef with Vegetables77
8ProgressoChicken Noodle484.590.075.03/07/2311/13/236/23/23OkProgressoChicken Noodle88
9Campbell'sChunky Beef with Vegetables276.077.075.03/04/236/16/237/04/23OkProgressoChicken Noodle90
108/01/23ErrorCampbell'sTomato
119/01/23ErrorProgressoLentil
129/25/23OkCampbell'sChunky Chicken Noodle93
1310/30/23OkProgressoChicken & Homestyle Noodles95
1411/13/23OkProgressoChicken Noodle75
1512/29/23OkCampbell'sChunky Chicken Noodle82
2-column compare
Cell Formulas
RangeFormula
D5:D9D5=COUNTIFS(TblLog[Brand],[@Brand],TblLog[Flavor],[@Flavor])
E5:E9E5= IF([@Count]>0,AVERAGEIFS(TblLog[Rating],TblLog[Brand],[@Brand],TblLog[Flavor],[@Flavor]),"n/a")
F5:F9F5= IF([@Count]>0,MAXIFS(TblLog[Rating],TblLog[Brand],[@Brand],TblLog[Flavor],[@Flavor]),"n/a")
G5:G9G5= IF([@Count]>0,MINIFS(TblLog[Rating],TblLog[Brand],[@Brand],TblLog[Flavor],[@Flavor]),"n/a")
H5:H9H5= IF([@Count]>0,MINIFS(TblLog[Date],TblLog[Brand],[@Brand],TblLog[Flavor],[@Flavor]),"n/a")
I5:I9I5= IF([@Count]>0,MAXIFS(TblLog[Date],TblLog[Brand],[@Brand],TblLog[Flavor],[@Flavor]),"n/a")
L5:L15L5=IF(COUNTIFS(TblProducts[Brand],[@Brand],TblProducts[Flavor],[@Flavor])=1,"Ok","Error")
 
Upvote 0

Forum statistics

Threads
1,215,101
Messages
6,123,096
Members
449,096
Latest member
provoking

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top