Countifs

jwgreen1986

Board Regular
Joined
Mar 8, 2019
Messages
64
Having a lot of issues trying to resolve this problem.
so i currently have 3 league tables. each league table is then automatically changed depending on the options selected from some drop downs.

  1. shows the sales of staff at a particular site. You have an option of new sales, used sales and then overall sales. you can then select the date drop down to change the month, (Jan - Dec and then an option for YTD). you can also select which site you want to show on this by the 3rd drop down.
  2. Shows a league table for sites. again you can change the criteria for this by changing the month or changing the sale type (the site drop down has no affect on this table)
  3. this table is an overall sales table. it shows every member of staff. This again can be changed to show the month and sales type (site drop down has no affect on this table either.

The issue i am having is with table 1. the table is there and set up. the issue i am having is there is a lot of #NUM ! in the table. this is because after the last person for the site it is bringing back num!s in the table which in turn is messing with the ranking system etc.

now i was thinking of using a countif formula at the beginning where it would count the amount of people at site, once the row is more than at site then it will start returning blanks and the table would therefore work.

The problem i have is splitting the new and used sales and counting these. if it was just a simple new/used it wouldnt be bad, but we also have staff that are classed as combined. this means they can sell both new and used.

so basically i want to create a count if at the beginning of my formula where it is like this

if new is selected in the drop down count the total number of new and combined staff at the site that is selected.
If used is selected in the drop down count the total number of used and combined staff at the site that is selected.
If overall is selected then count all the staff at the site selected.

any help with this would be fantastic
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
if new is selected in the drop down count the total number of new and combined staff at the site that is selected.
If used is selected in the drop down count the total number of used and combined staff at the site that is selected.
If overall is selected then count all the staff at the site selected.

Hi, something like this maybe?


Excel 2013/2016
ABCDEF
1Sitesale typeSiteSale Typecount
2AnewAnew2
3AusedAused4
4AcombinedAoverall5
5Bcombined
6Bcombined
7Bused
8Bcombined
9Aused
10Aused
11Bnew
Sheet1
Cell Formulas
RangeFormula
F2=COUNTIFS(A:A,D2,B:B,IF(E2="overall","*",E2),B:B,"<>combined")+COUNTIFS(A:A,D2,B:B,"combined")
 
Upvote 0
hi thanks,

however i dont want it to actually tell me how many sales there has been at the site, i want it to list the people at site. This is the little table i have at the min. the formula i use to drag the name is also below (the rest is a vlookup)

The issue i have is that i know there are 8 staff that are classed as used at Derby (5 used and 3 combined) but it only brings 5 spots back in the table (im assuming it is only recognising 5 used staff and not including the 3 combined)

it is similar with the overall tab. when overall is selected i need it to show all the staff at site or bring their names back.

NameSiteSales
W1Derby7
W2Derby5
w3Derby4
w4Derby
w5Derby

<tbody>
[TH="align: center"]A[/TH]
[TH="align: center"]B[/TH]
[TH="align: center"]C[/TH]
[TH="align: center"]D[/TH]
[TH="align: center"]E[/TH]
[TH="align: center"][/TH]

[TD="align: center"]Rank[/TD]

[TD="align: right"]Scheme[/TD]

[TD="align: center"]1[/TD]

[TD="align: right"]Used[/TD]

[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]Combined[/TD]

[TD="align: right"][/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]Used[/TD]

[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]Used[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]Used[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Code used to get name
=IF(ROWS(DA$4:DA4)>(COUNTIFS($D$4:$D$201,Standings!$D$7,$E$4:$E$201,Standings!$D$5)),"",IF(Standings!$D$5="Used",INDEX(Table!$BD$4:$BD$202,SMALL(IF(Standings!$D$7=Table!$BC$4:$BC$202,ROW(Table!$BC$4:$BC$202)-ROW(Table!$DA$4)+1),ROW(1:1))),IF(Standings!$D$5="New",INDEX(Table!$AR$4:$AR$201,SMALL(IF(Standings!$D$7=Table!$AQ$4:$AQ$202,ROW(Table!$AR$4:$AR$202)-ROW(Table!$DA$4)+1),ROW(1:1))),IF(Standings!$D$5="Overall",INDEX(Table!$DH$4:$DH$201,SMALL(IF(Standings!$D$7=Table!$DJ$4:$DJ$202,ROW(Table!$DH$4:$DH$202)-ROW(Table!$DA$4)+1),ROW(1:1))),""))))

*Edited*
Standings!D5 in the formula references the drop down to select which scheme you want the table to show (New, Used, Overall)
Standings!D7 is the drop down for the site.

i need something to replace $E$4:$E$201,Standings!$D$5 so it will be something like if Standings!$D$5 = Used then countif $E$4:$E$201,"Used" or "Combined"

if Standings!$D$5 = New then countif $E$4:$E$201,"New" or "Combined"

if Standings!$D$5 = Overall then countif $E$4:$E$201,"New" or "Combined" or "Used"

so as it stands the table, when new is selected it will only bring up 6 staff (9 are new in total) it looks like it brings the staff in alphabetically as well from my payroll list.

when used is selected it will only bring back 5 staff (8 are used in total)

when overall is selected it is bring none back.

it is the same with every site. it only brings back the same number it counts for new or used staff at each site and is not including any combined ones.
 
Last edited:
Upvote 0
i dont want it to actually tell me how many sales there has been at the site, i want it to list the people at site.

I think it was all the talk of counting and countifs() that confused :eek:

See if you can adapt this to your set up - for efficiency reason it's better to have the COUNTIFS() function outside of the formula that returns the list.


Excel 2013/2016
CDEF
4Name list
5Schemeneww4
6w6
7SiteDerbyw7
8
9Helper3
10
11
12
Standings
Cell Formulas
RangeFormula
F5=IF(ROWS(F$5:F5)>$D$9,"",INDEX(table!$B$2:$B$11,SMALL(IF(table!$C$2:$C$11=$D$7,IF(IF($D$5="overall",1,ISNUMBER(MATCH(table!$D$2:$D$11,CHOOSE({1,2},"combined",$D$5),0))),ROW(table!$B$2:$B$11)-MIN(ROW(table!$B$2:$B$11))+1)),ROWS(F$5:F5))))
D9=COUNTIFS(table!C:C,D7,table!D:D,IF(D5="overall","*",D5),table!D:D,"<>combined")+COUNTIFS(table!C:C,D7,table!D:D,"combined")




Excel 2013/2016
ABCDE
1RankNameSiteSchemeSales
21W1DerbyUsed7
32W2DerbyCombined5
43w3DerbyUsed4
54w4DerbyUsed4
65w5DerbyUsed2
76w6Derbynew
87w7Derbynew
98
109
1110
table
 
Last edited:
Upvote 0
Hi,

can you explain the formulas a little more. i understand the helper bit and what you are doing, just not the formula in there. it looks to me like it is just looking at the "Overall" option in the drop down and isnt considering the new or used par of the drop down.

I think it was all the talk of counting and countifs() that confused :eek:

See if you can adapt this to your set up - for efficiency reason it's better to have the COUNTIFS() function outside of the formula that returns the list.

Excel 2013/2016
CDEF
Name list
Schemenew
w6
SiteDerbyw7
Helper

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFF00]#FFFF00[/URL] "]w4[/TD]

[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFF00]#FFFF00[/URL] , align: right"]3[/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]12[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Standings

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]F5[/TH]
[TD="align: left"]=IF(ROWS(F$5:F5)>$D$9,"",INDEX(table!$B$2:$B$11,SMALL(IF(table!$C$2:$C$11=$D$7,IF(IF($D$5="overall",1,ISNUMBER(MATCH(table!$D$2:$D$11,CHOOSE({1,2},"combined",$D$5),0))),ROW(table!$B$2:$B$11)-MIN(ROW(table!$B$2:$B$11))+1)),ROWS(F$5:F5))))[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]D9[/TH]
[TD="align: left"]=COUNTIFS(table!C:C,D7,table!D:D,IF(D5="overall","*",D5),table!D:D,"<>combined")+COUNTIFS(table!C:C,D7,table!D:D,"combined")[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]




Excel 2013/2016
ABCDE
RankNameSiteSchemeSales
W1DerbyUsed
W2DerbyCombined
w3DerbyUsed
w4DerbyUsed
w5DerbyUsed
w6Derbynew
w7Derbynew

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]1[/TD]

[TD="align: right"]7[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]2[/TD]

[TD="align: right"]5[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]3[/TD]

[TD="align: right"]4[/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]4[/TD]

[TD="align: right"]4[/TD]

[TD="align: center"]6[/TD]
[TD="align: right"]5[/TD]

[TD="align: right"]2[/TD]

[TD="align: center"]7[/TD]
[TD="align: right"]6[/TD]

[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="align: right"]7[/TD]

[TD="align: right"][/TD]

[TD="align: center"]9[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
table
 
Upvote 0
so what i want this table to do is
when i select New on the drop down from my standings tab (Standings!$D$5) it will list all the staff at the chosen site that are either on the New scheme or combined scheme for the chosen site (Standings!$D$7)

When i change the drop down to Used i want it to show all the staff that are on the Used scheme or combined scheme for the chosen site (Standings!$D$7)

When overall is picked i want it to show ever member of staff that work at the chosen site. (Standings!$D$7)
 
Upvote 0
Hi thanks for the reply.
tried the formula to generate the number. got a #Value error

=COUNTIFS($D$4:$D$201,Standings!$D$7,Table!$E$4:$E$201,IF(Standings!$D$5="Overall","*",Standings!$D$5),Table!$E$4:$E$20,"<>Combined")+COUNTIFS(Table!$D$4:$D$201,Standings!$D$7,Table!$E$4:$E$201,"Combined")
 
Upvote 0
=COUNTIFS($D$4:$D$201,Standings!$D$7,Table!$E$4:$E$201,IF(Standings!$D$5="Overall","*",Standings!$D$5),Table!$E$4:$E$20,"<>Combined")+COUNTIFS(Table!$D$4:$D$201,Standings!$D$7,Table!$E$4:$E$201,"Combined")

Typo in red?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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