calculating attendance percentage based on the number of days in a week worked

Plasmech

New Member
Joined
Oct 26, 2021
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Say I have a spreadsheet with a column for the date and a column for the number of hours worked. The spreadsheet will be limited to one calendar year.

I want to add an "attendance" column. To achieve perfect (100% attendance), one must have hours (any nonzero number of hours) logged for Tuesday, Wednesday, and Thursday of each week.

example:

DATE HOURS ATT (%)
02/02/24 3 100
02/03/24 3 100
02/04/24 3 100
02/09/24 2 100
02/10/24 0 80
02/11/24 3 83.3


What would the best way to "code" this be?

Thanks.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Assuming the dates are in order:

Book1
ABC
1DateHoursAtt (%)
21/2/20243100.00%
31/3/20242100.00%
41/4/20243100.00%
51/9/20242100.00%
61/10/2024080.00%
71/11/2024383.33%
81/12/2024183.33%
91/13/2024183.33%
101/14/2024183.33%
111/15/2024183.33%
121/16/2024071.43%
131/17/2024175.00%
141/18/2024177.78%
151/19/2024177.78%
161/20/2024177.78%
Sheet4
Cell Formulas
RangeFormula
C2:C16C2=ROWS(FILTER(A$2:A2,(WEEKDAY(A$2:A2,12)<4)*(B$2:B2>0)))/((WEEKNUM(A2,12)-2)*3+MIN(WEEKDAY(A2,12),3))
Named Ranges
NameRefers ToCells
RangeOne=Sheet4!$B$3:$E$6C3:C16


I also assumed your example was in January, since February 2,3,4 are not Tuesday through Thursday.
 
Upvote 0
How about this?:

Book1
ABCD
1DateHours
21/1/2024 Mon372.6% (114 of 157)
31/2/2024 Tue0
41/3/2024 Wed3
51/4/2024 Thu0
61/5/2024 Fri3
71/6/2024 Sat3
81/7/2024 Sun3
91/8/2024 Mon2
101/9/2024 Tue1
111/10/2024 Wed2
121/11/2024 Thu2
131/12/2024 Fri1
141/13/2024 Sat2
151/14/2024 Sun0
Sheet1
Cell Formulas
RangeFormula
A2:A367A2=SEQUENCE(366,,DATE(2024,1,1))
B2:B367B2=RANDARRAY(366,,0,3,1)
D2D2=LET( rd,A2:A3670, rh,B2:B3670, d, FILTER(rd,rd<>""), h, FILTER(rh,rh<>""), res,FILTER(h,d=WORKDAY.INTL(d-1,1,"1000111")), totalNumberOfDays, COUNT(res), workedDays, COUNT(FILTER(res,res<>0)), TEXT(workedDays/totalNumberOfDays,"0.0%") &" ("& workedDays &" of "&totalNumberOfDays & ")" )
Dynamic array formulas.
 
Upvote 0
Assuming the dates are in order:

Book1
ABC
1DateHoursAtt (%)
21/2/20243100.00%
31/3/20242100.00%
41/4/20243100.00%
51/9/20242100.00%
61/10/2024080.00%
71/11/2024383.33%
81/12/2024183.33%
91/13/2024183.33%
101/14/2024183.33%
111/15/2024183.33%
121/16/2024071.43%
131/17/2024175.00%
141/18/2024177.78%
151/19/2024177.78%
161/20/2024177.78%
Sheet4
Cell Formulas
RangeFormula
C2:C16C2=ROWS(FILTER(A$2:A2,(WEEKDAY(A$2:A2,12)<4)*(B$2:B2>0)))/((WEEKNUM(A2,12)-2)*3+MIN(WEEKDAY(A2,12),3))
Named Ranges
NameRefers ToCells
RangeOne=Sheet4!$B$3:$E$6C3:C16


I also assumed your example was in January, since February 2,3,4 are not Tuesday through Thursday.
Hi Eric,

Thanks! This worked perfectly.

Yes, I meant to type January (01) dates. I tried to edit my post, but apparently, that function does not exist on this forum.

I am not familiar with "Names Ranges", nor did I need it/them to get your logic to work. Would you care to explain?

Thanks again.
 
Upvote 0
How about this?:

Book1
ABCD
1DateHours
21/1/2024 Mon372.6% (114 of 157)
31/2/2024 Tue0
41/3/2024 Wed3
51/4/2024 Thu0
61/5/2024 Fri3
71/6/2024 Sat3
81/7/2024 Sun3
91/8/2024 Mon2
101/9/2024 Tue1
111/10/2024 Wed2
121/11/2024 Thu2
131/12/2024 Fri1
141/13/2024 Sat2
151/14/2024 Sun0
Sheet1
Cell Formulas
RangeFormula
A2:A367A2=SEQUENCE(366,,DATE(2024,1,1))
B2:B367B2=RANDARRAY(366,,0,3,1)
D2D2=LET( rd,A2:A3670, rh,B2:B3670, d, FILTER(rd,rd<>""), h, FILTER(rh,rh<>""), res,FILTER(h,d=WORKDAY.INTL(d-1,1,"1000111")), totalNumberOfDays, COUNT(res), workedDays, COUNT(FILTER(res,res<>0)), TEXT(workedDays/totalNumberOfDays,"0.0%") &" ("& workedDays &" of "&totalNumberOfDays & ")" )
Dynamic array formulas.
Thank you, Felix. Very powerful. Thank you for putting the effort into this.

I need a running attendance, not a single, current value.
 
Upvote 0
Oh, my mistake. Sorry.
Just curious. What are those percentages used for? Or how are they used later on?
 
Upvote 0
Hi Eric,

Thanks! This worked perfectly.

Yes, I meant to type January (01) dates. I tried to edit my post, but apparently, that function does not exist on this forum.

I am not familiar with "Names Ranges", nor did I need it/them to get your logic to work. Would you care to explain?

Thanks again.
Sorry about the named range! That was leftover from another problem I was working on, on the same sheet. It's not visible on the sheet, so I didn't notice it until after I posted. Just ignore it, it has nothing to do with your answer.

Anyway, glad we could help! 😀
 
Upvote 0
Sorry about the named range! That was leftover from another problem I was working on, on the same sheet. It's not visible on the sheet, so I didn't notice it until after I posted. Just ignore it, it has nothing to do with your answer.

Anyway, glad we could help! 😀
Hi Eric,

Sorry to bother you again. How would I changed the days from Tue, Wed, Thurs to Tue, Wed, Sat?

In addition to actually needing the days changed, this will help me understand how the logic works.

Thanks.
 
Upvote 0
Hi Eric,

Sorry to bother you again. How would I changed the days from Tue, Wed, Thurs to Tue, Wed, Sat?

In addition to actually needing the days changed, this will help me understand how the logic works.

Thanks.
Tues, Wed, Sat makes it trickier! But it's not too big of a change, and maybe it makes it a bit easier to understand. Try:

Book1
ABCD
1DateHoursAtt (%)
21/2/20243100.00%Tuesday
31/3/20242100.00%Wednesday
41/4/20243100.00%Thursday
51/9/2024275.00%Tuesday
61/10/2024060.00%Wednesday
71/11/2024360.00%Thursday
81/12/2024160.00%Friday
91/13/2024166.67%Saturday
101/14/2024166.67%Sunday
111/15/2024166.67%Monday
121/16/2024057.14%Tuesday
131/17/2024162.50%Wednesday
141/18/2024162.50%Thursday
151/19/2024162.50%Friday
161/20/2024166.67%Saturday
17#DIV/0!
Sheet4
Cell Formulas
RangeFormula
D2:D16D2=TEXT(A2,"dddd")
C2:C17C2=SUM(ISNUMBER(MATCH(WEEKDAY(A$2:A2),{3,4,7},0))*(B$2:B2>0))/((WEEKNUM(A2)-1)*3+VLOOKUP(WEEKDAY(A2),{1,0;3,1;4,2;7,3},2))


A percentage is basically a ratio of valid days divided by total number of possible days. The numerator part of the formula is:

SUM(ISNUMBER(MATCH(WEEKDAY(A$2:A2),{3,4,7},0))*(B$2:B2>0))

The A$2:A2 construct is basically an expanding range as you drag the formula down the column, so it includes the current row, and all the rows above it. The MATCH looks at the WEEKDAY of each date in column A, and if it is 3, 4, or 7 it returns a number, otherwise an error. The ISNUMBER turns that into TRUE or FALSE. Then the B$2:B2>0 part looks at the hours to make sure they're >0 and returns TRUE or FALSE. When you multiply those together, you get 1 or 0, and the SUM adds up the 1s. These are the valid days. (In the original formula I used FILTER, which still works, but this is a tad shorter.)

To get the denominator,

((WEEKNUM(A2)-1)*3+VLOOKUP(WEEKDAY(A2),{1,0;3,1;4,2;7,3},2))

The WEEKNUM gives you the week of the year so far. Subtract 1, and that's the number of previous weeks, multiply by 3 (for Tue,Wed,Sat) to get the number of possible days before this week. The VLOOKUP tells us how many possible days are in the current week. The embedded table basically says that Sun-Mon, we add 0. Tue, we add 1. Wed-Fri we add 2, Sat we add 3. I don't especially like the embedded table, but it's better than a complicate IF structure.

So that's the gist of it! Hope it helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,125
Messages
6,123,195
Members
449,090
Latest member
bes000

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