Why is this one CountIfs expression getting a Value error?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,687
Office Version
  1. 365
Platform
  1. Windows
I was working on a workbook to keep track of my ratings of various items I purchase. I ran into a curious problem in the snack bar sheet that I cannot figure out.

I have 2 tables. The Product table (TblProdSB) is a list of the products (snack bars in this sheet). The Log table (TblLogSB) is a list of the ratings each time I try one of the snack bars. I have simplified the tables. In all my other sheets with similar tables, if I add a new product to the Product table, the count will show zero. For some reason, this one gets a Value error. I am going to include 3 minisheets to show how this error disappears and then reappears.

Minisheet #1: Value error in D8

CountIf.xlsx
BCDEFGHIJ
3Product TableUsage Log Table
4BrandFlavor# TriedDateOK?BrandFlavorRating
5KindDark Chocolate Nuts & Sea Salt15/30/24OkKindDark Chocolate Nuts & Sea Salt82
6KindDark Chocolate Cherry Cashew15/30/24OkKindDark Chocolate Cherry Cashew88
7KindBreakfast Bars15/29/21OkKindBreakfast Bars40
8KindDark Chocolate Mint#VALUE!
Snack Bars
Cell Formulas
RangeFormula
G5:G7G5=IF(COUNTIFS(TblProdSB[Brand],[@Brand],TblProdSB[Flavor],[@Flavor])=1,"Ok","XXX")
D5:D8D5=COUNTIFS(TblLogSB[@Brand],[@Brand],TblLogSB[@Flavor],[@Flavor])


Minisheet #2: If I add a row to the Log table (on the right), the error disappears

CountIf.xlsx
BCDEFGHIJ
3Product TableUsage Log Table
4BrandFlavor# TriedDateOK?BrandFlavorRating
5KindDark Chocolate Nuts & Sea Salt15/30/24OkKindDark Chocolate Nuts & Sea Salt82
6KindDark Chocolate Cherry Cashew15/30/24OkKindDark Chocolate Cherry Cashew88
7KindBreakfast Bars15/29/21OkKindBreakfast Bars40
8KindDark Chocolate Mint0XXX
Snack Bars
Cell Formulas
RangeFormula
D5:D8D5=COUNTIFS(TblLogSB[@Brand],[@Brand],TblLogSB[@Flavor],[@Flavor])
G5:G8G5=IF(COUNTIFS(TblProdSB[Brand],[@Brand],TblProdSB[Flavor],[@Flavor])=1,"Ok","XXX")


Minisheet #3: If I add a new row to the Product table (on the left), the error reappears.

CountIf.xlsx
BCDEFGHIJ
3Product TableUsage Log Table
4BrandFlavor# TriedDateOK?BrandFlavorRating
5KindDark Chocolate Nuts & Sea Salt15/30/24OkKindDark Chocolate Nuts & Sea Salt82
6KindDark Chocolate Cherry Cashew15/30/24OkKindDark Chocolate Cherry Cashew88
7KindBreakfast Bars15/29/21OkKindBreakfast Bars40
8KindDark Chocolate Mint0XXX
9#VALUE!
Snack Bars
Cell Formulas
RangeFormula
G5:G8G5=IF(COUNTIFS(TblProdSB[Brand],[@Brand],TblProdSB[Flavor],[@Flavor])=1,"Ok","XXX")
D5:D9D5=COUNTIFS(TblLogSB[@Brand],[@Brand],TblLogSB[@Flavor],[@Flavor])


What is going on here?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
The formula in col D is wrong, it should be like the countifs in col G
 
Upvote 0
Solution
Ok, I see it now. The expression

Excel Formula:
=COUNTIFS(TblLogSB[@Brand],[@Brand],TblLogSB[@Flavor],[@Flavor])

has an "@" symbol in both criteria parameters, which means it is only testing one row, not the entire column. The correct expression should have been

Excel Formula:
=COUNTIFS(TblLogSB[Brand],[@Brand],TblLogSB[Flavor],[@Flavor])

It now works.

Thanks
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
In case anyone is interested, this example shows two Product tables. The one on the left has the incorrect CountIfs expression. The one in the middle has the correct expression. I was confused by the seemingly correct counts in the # Tried column. But that was just an unfortunate accident in that the values in the Brand and Flavor columns were in the same rows.

CountIf.xlsx
BCDEFGHIJKLMN
3Incorrect Product Table (TblProdSBErr)Correct Product Table (TblProdSBOk)Usage Log Table (TblLogSB)
4BrandFlavor# TriedBrandFlavor# TriedDateOK?BrandFlavorRating
5KindDark Chocolate Nuts & Sea Salt1KindDark Chocolate Nuts & Sea Salt15/30/24OkKindDark Chocolate Nuts & Sea Salt91
6KindDark Chocolate Cherry Cashew1KindDark Chocolate Cherry Cashew15/30/24OkKindDark Chocolate Cherry Cashew82
7KindBreakfast Bars1KindBreakfast Bars15/30/24OkKindBreakfast Bars88
8KindDark Chocolate Mint1KindDark Chocolate Mint15/30/24OkKindDark Chocolate Mint85
9#VALUE!0
Snack Bars
Cell Formulas
RangeFormula
K5:K8K5=IF(COUNTIFS(TblProdSBOk[Brand],[@Brand],TblProdSBOk[Flavor],[@Flavor])=1,"Ok","XXX")
D5:D9D5=COUNTIFS(TblLogSB[@Brand],[@Brand],TblLogSB[@Flavor],[@Flavor])
H5:H9H5=COUNTIFS(TblLogSB[Brand],[@Brand],TblLogSB[Flavor],[@Flavor])
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,157
Members
452,615
Latest member
bogeys2birdies

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