Countifs

jwgreen1986

Board Regular
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
 

FormR

MrExcel MVP
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?

<b>Excel 2013/2016</b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">1</td><td style=";">Site</td><td style=";">sale type</td><td style="text-align: right;;"></td><td style=";">Site</td><td style=";">Sale Type</td><td style=";">count</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">2</td><td style=";">A</td><td style=";">new</td><td style="text-align: right;;"></td><td style=";">A</td><td style=";">new</td><td style="text-align: right;background-color: #FFFF00;;">2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">3</td><td style=";">A</td><td style=";">used</td><td style="text-align: right;;"></td><td style=";">A</td><td style=";">used</td><td style="text-align: right;;">4</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style=";">A</td><td style=";">combined</td><td style="text-align: right;;"></td><td style=";">A</td><td style=";">overall</td><td style="text-align: right;;">5</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">5</td><td style=";">B</td><td style=";">combined</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">6</td><td style=";">B</td><td style=";">combined</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">7</td><td style=";">B</td><td style=";">used</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">8</td><td style=";">B</td><td style=";">combined</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">9</td><td style=";">A</td><td style=";">used</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">10</td><td style=";">A</td><td style=";">used</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">11</td><td style=";">B</td><td style=";">new</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr></tbody></table><p style="width:4.8em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Sheet1</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">F2</th><td style="text-align:left">=COUNTIFS(<font color="Blue">A:A,D2,B:B,IF(<font color="Red">E2="overall","*",E2</font>),B:B,"<>combined"</font>)+COUNTIFS(<font color="Blue">A:A,D2,B:B,"combined"</font>)</td></tr></tbody></table></td></tr></table><br />
 

jwgreen1986

Board Regular
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.

ABCDE
RankNameSiteSchemeSales
1W1DerbyUsed7
2W2DerbyCombined5
3w3DerbyUsed4
4w4DerbyUsed4
5w5DerbyUsed2
6
7
8
9
10

<tbody>
</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:

FormR

MrExcel MVP
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.

<b>Excel 2013/2016</b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>C</th><th>D</th><th>E</th><th>F</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">Name list</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">5</td><td style=";">Scheme</td><td style=";">new</td><td style="text-align: right;;"></td><td style="background-color: #FFFF00;;">w4</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">6</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">w6</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">7</td><td style=";">Site</td><td style=";">Derby</td><td style="text-align: right;;"></td><td style=";">w7</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">8</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">9</td><td style=";">Helper</td><td style="text-align: right;background-color: #FFFF00;;">3</td><td style="text-align: right;;"></td><td style=";"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">10</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">11</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">12</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";"></td></tr></tbody></table><p style="width:7.2em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Standings</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">F5</th><td style="text-align:left">=IF(<font color="Blue">ROWS(<font color="Red">F$5:F5</font>)>$D$9,"",INDEX(<font color="Red">table!$B$2:$B$11,SMALL(<font color="Green">IF(<font color="Purple">table!$C$2:$C$11=$D$7,IF(<font color="Teal">IF(<font color="#FF00FF">$D$5="overall",1,ISNUMBER(<font color="Navy">MATCH(<font color="Blue">table!$D$2:$D$11,CHOOSE(<font color="Red">{1,2},"combined",$D$5</font>),0</font>)</font>)</font>),ROW(<font color="#FF00FF">table!$B$2:$B$11</font>)-MIN(<font color="#FF00FF">ROW(<font color="Navy">table!$B$2:$B$11</font>)</font>)+1</font>)</font>),ROWS(<font color="Purple">F$5:F5</font>)</font>)</font>)</font>)</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">D9</th><td style="text-align:left">=COUNTIFS(<font color="Blue">table!C:C,D7,table!D:D,IF(<font color="Red">D5="overall","*",D5</font>),table!D:D,"<>combined"</font>)+COUNTIFS(<font color="Blue">table!C:C,D7,table!D:D,"combined"</font>)</td></tr></tbody></table></td></tr></table><br />


<b>Excel 2013/2016</b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">1</td><td style=";">Rank</td><td style=";">Name</td><td style=";">Site</td><td style=";">Scheme</td><td style=";">Sales</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">2</td><td style="text-align: right;;">1</td><td style=";">W1</td><td style=";">Derby</td><td style=";">Used</td><td style="text-align: right;;">7</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">3</td><td style="text-align: right;;">2</td><td style=";">W2</td><td style=";">Derby</td><td style=";">Combined</td><td style="text-align: right;;">5</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style="text-align: right;;">3</td><td style=";">w3</td><td style=";">Derby</td><td style=";">Used</td><td style="text-align: right;;">4</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">5</td><td style="text-align: right;;">4</td><td style=";">w4</td><td style=";">Derby</td><td style=";">Used</td><td style="text-align: right;;">4</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">6</td><td style="text-align: right;;">5</td><td style=";">w5</td><td style=";">Derby</td><td style=";">Used</td><td style="text-align: right;;">2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">7</td><td style="text-align: right;;">6</td><td style=";">w6</td><td style=";">Derby</td><td style=";">new</td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">8</td><td style="text-align: right;;">7</td><td style=";">w7</td><td style=";">Derby</td><td style=";">new</td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">9</td><td style="text-align: right;;">8</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">10</td><td style="text-align: right;;">9</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">11</td><td style="text-align: right;;">10</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr></tbody></table><p style="width:4em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">table</p><br /><br />
 
Last edited:

jwgreen1986

Board Regular
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
4Name list
5Schemeneww4
6w6
7SiteDerbyw7
8
9Helper3
10
11
12

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Standings

Worksheet Formulas
CellFormula
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")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>




Excel 2013/2016
ABCDE
1RankNameSiteSchemeSales
21W1DerbyUsed7
32W2DerbyCombined5
43w3DerbyUsed4
54w4DerbyUsed4
65w5DerbyUsed2
76w6Derbynew
87w7Derbynew
98
109
1110

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
table
 

jwgreen1986

Board Regular
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)
 

jwgreen1986

Board Regular
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")
 

FormR

MrExcel MVP
=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:

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top