Could not find a suitable solution, hence this post.
Have 2 sheets - Attendance & Payroll where attendance is filled in a pivoted manner (see sample).
For a given date range, I want to count the number of "Absent" days for the staff. The Non-Array-Formula (in Payroll column "Absent") below does that. Note: column A with staff ids is a dynamic list even though its fixed in the sample.
How this formula works:
- match the payroll-staffid to the attendance column-header-staffid using MATCH
- date range given in cells payroll B1,B2
- Settings!$B$13 contains the columnar range as per (2)
- OFFSET (3) by MATCH to get the staff attendance
- COUNTIF the number of "Absent" entries in staff attendance range - CORRECT
- ArrayFormula does NOT work when the payroll-staffid "A5" is changed to "A5:A15"
Note: there is no guarantee that payroll-staffids order and attendence-header-staffids are both in same order -> that's why each staffid is mapped MATCHed and OFFSET.
=COUNTIF(OFFSET(INDIRECT(Settings!$B$13),0,MATCH(A5,Attendance!$B$1:$1,FALSE)),"Absent")
Sample sheet here.