Is there a way to filter the rows used in a COUNTIF function?

R0502 20 Reputation points
2025-07-28T14:08:28.26+00:00

Hi!

I'm trying to make a tool to auto-review absence and sickness in the team, and I can't for the life of me figure out how to count absence totals the way I want to. I've made a (much) smaller fake sample to try and explain what I want to do:

User's image

I need to get the total, by "Grade" of sick days taken (i.e., a table with the Grades as column headings and the sick day totals for each on a row underneath) Ideally, I'd like to be able to use a formula that can find all the Grade 1 staff, for example, then count all the cells containing SICK (as one example, there are other types I would also need to count) in those rows. I've tried COUNTIFS but that just kept returning 0 or errors since the "Grade" range was fewer columns than the data I wanted to count, and there are wayyyyyyy too many columns and absence types to do it column by column. To my understanding INDEX(MATCH()) wouldn't work either as it can only find one row? Help is much appreciated!

Microsoft 365 and Office | Excel | For business | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2025-07-28T14:41:10.1466667+00:00

    Let's say you have Grades in B3:B13 and codes in C3:H13.

    For the summary, Grades 1 to 5 are in C15:G15.

    In C16: =SUM(($B$3:$B$13=C15)*($C$3:$H$13="SICK"))

    Fill to the right.

    User's image

    0 comments No comments

  2. Ashish Mathur 100.8K Reputation points Volunteer Moderator
    2025-08-13T23:19:58.6533333+00:00

    Hi,

    In cell I1, enter this formula

    =PIVOTBY(,A2:A12,BYROW(B2:G12,LAMBDA(a,COUNTIF(a,"sick"))),SUM)

    Hope this helps.

    User's image

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.