IF and AND function with COUNTIF to calculate only populated cells

VKiprijan

New Member
Joined
Feb 24, 2021
Messages
40
Office Version
  1. 2016
Platform
  1. Windows
Hello Everyone,

In the attached table for Soccer League, I am trying to come up with a formula that will count only the home and away games that have been played (CD for home and CL for away columns, the formula is =COUNTIF($C$5:$C$346,BQ7)), not all the games in the season. For example, the whole season has 34 weeks and I want the ranking based only on the 31 week that was played. The existing formula is showing the exact points and ranking only if I remove the remaining games that I have put as fixtures. If I keep these upcoming games, the table counts all the games I listed as played which is wrong. Basically, I want the formula that will work properly with all the soccer games in one season, finished ones and the upcoming ones.
I guess I should use the IF and AND in conjunction with the COUNTIF function to be able to set the scores in the first half and the second half of the games (columns D, E, F and G) as criteria for counting these games played. Can someone write me how the formula should look like?

Cell Formulas
RangeFormula
BR7:BR24BR7=RANK(CC7,$CC$7:$CC$24)
BS7:BS24BS7=SUMPRODUCT(($BR$7:$BR$24=$BR7)*($CB$7:$CB$24>CB7))
BT7:BT24BT7=SUMPRODUCT(($BR$7:$BR$24=$BR7)*($BS$7:$BS$24=$BS7)*($BZ$7:$BZ$24>BZ7))
BU7:BU24BU7=SUMPRODUCT(($BR$7:$BR$24=$BR7)*($BS$7:$BS$24=$BS7)*($BT$7:$BT$24=$BT7)*($CP$7:$CP$24>CP7))
BV7:CC24BV7=CD7+CL7
CD7:CD24CD7=COUNTIF($C$5:$C$346,BQ7)
CE7:CE24CE7=SUMPRODUCT(($C$5:$C$346=BQ7)*($F$5:$F$346>$G$5:$G$346))
CF7:CF24CF7=SUMPRODUCT(($C$5:$C$346=BQ7)*($F$5:$F$346=$G$5:$G$346)*($F$5:$F$346<>""))
CG7:CG24CG7=SUMPRODUCT(($C$5:$C$346=BQ7)*($F$5:$F$346<$G$5:$G$346))
CH7:CH24CH7=SUMIF($C$5:$C$346,BQ7,$F$5:$F$346)
CI7:CI24CI7=SUMIF($C$5:$C$346,BQ7,$G$5:$G$346)
CJ7:CJ24,CR7:CR24CJ7=CH7-CI7
CK7:CK24,CS7:CS24CK7=CE7*3+CF7*1
CL7:CL24CL7=COUNTIF($H$5:$H$346,BQ7)
CM7:CM24CM7=SUMPRODUCT(($H$5:$H$346=BQ7)*($F$5:$F$346<$G$5:$G$346))
CN7:CN24CN7=SUMPRODUCT(($H$5:$H$346=BQ7)*($F$5:$F$346=$G$5:$G$346))
CO7:CO24CO7=SUMPRODUCT(($H$5:$H$346=BQ7)*($F$5:$F$346>$G$5:$G$346))
CP7:CP24CP7=SUMIF($H$5:$H$346,BQ7,$G$5:$G$346)
CQ7:CQ24CQ7=SUMIF($H$5:$H$346,BQ7,$F$5:$F$346)
BP7:BP24BP7=SUM(BR7:BU7)




Thank you in advance.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi VK
change your countif() to countifs() and you can include multiple criteria, then your second criteria can look at the date of the game or something suitable to identify the games to count or a date range
 
Upvote 0
Solution
Hello Everyone,

In the attached table for Soccer League, I am trying to come up with a formula that will count only the home and away games that have been played (CD for home and CL for away columns, the formula is =COUNTIF($C$5:$C$346,BQ7)), not all the games in the season. For example, the whole season has 34 weeks and I want the ranking based only on the 31 week that was played. The existing formula is showing the exact points and ranking only if I remove the remaining games that I have put as fixtures. If I keep these upcoming games, the table counts all the games I listed as played which is wrong. Basically, I want the formula that will work properly with all the soccer games in one season, finished ones and the upcoming ones.
I guess I should use the IF and AND in conjunction with the COUNTIF function to be able to set the scores in the first half and the second half of the games (columns D, E, F and G) as criteria for counting these games played. Can someone write me how the formula should look like?

Cell Formulas
RangeFormula
BR7:BR24BR7=RANK(CC7,$CC$7:$CC$24)
BS7:BS24BS7=SUMPRODUCT(($BR$7:$BR$24=$BR7)*($CB$7:$CB$24>CB7))
BT7:BT24BT7=SUMPRODUCT(($BR$7:$BR$24=$BR7)*($BS$7:$BS$24=$BS7)*($BZ$7:$BZ$24>BZ7))
BU7:BU24BU7=SUMPRODUCT(($BR$7:$BR$24=$BR7)*($BS$7:$BS$24=$BS7)*($BT$7:$BT$24=$BT7)*($CP$7:$CP$24>CP7))
BV7:CC24BV7=CD7+CL7
CD7:CD24CD7=COUNTIF($C$5:$C$346,BQ7)
CE7:CE24CE7=SUMPRODUCT(($C$5:$C$346=BQ7)*($F$5:$F$346>$G$5:$G$346))
CF7:CF24CF7=SUMPRODUCT(($C$5:$C$346=BQ7)*($F$5:$F$346=$G$5:$G$346)*($F$5:$F$346<>""))
CG7:CG24CG7=SUMPRODUCT(($C$5:$C$346=BQ7)*($F$5:$F$346<$G$5:$G$346))
CH7:CH24CH7=SUMIF($C$5:$C$346,BQ7,$F$5:$F$346)
CI7:CI24CI7=SUMIF($C$5:$C$346,BQ7,$G$5:$G$346)
CJ7:CJ24,CR7:CR24CJ7=CH7-CI7
CK7:CK24,CS7:CS24CK7=CE7*3+CF7*1
CL7:CL24CL7=COUNTIF($H$5:$H$346,BQ7)
CM7:CM24CM7=SUMPRODUCT(($H$5:$H$346=BQ7)*($F$5:$F$346<$G$5:$G$346))
CN7:CN24CN7=SUMPRODUCT(($H$5:$H$346=BQ7)*($F$5:$F$346=$G$5:$G$346))
CO7:CO24CO7=SUMPRODUCT(($H$5:$H$346=BQ7)*($F$5:$F$346>$G$5:$G$346))
CP7:CP24CP7=SUMIF($H$5:$H$346,BQ7,$G$5:$G$346)
CQ7:CQ24CQ7=SUMIF($H$5:$H$346,BQ7,$F$5:$F$346)
BP7:BP24BP7=SUM(BR7:BU7)




Thank you in advance.
Hi VK
change your countif() to countifs() and you can include multiple criteria, then your second criteria can look at the date of the game or something suitable to identify the games to count or a date range
Yes, that's what I did and it finally works. Thanks a lot.
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,120
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