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.
 
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!
@Eric W

This worked beautifully! Thank you so much.

I think I understand how it works now, too. A bit tricky, but I don't see an easier way.

Thanks again for putting forth all this effort.

Much appreciated!
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,215,129
Messages
6,123,214
Members
449,091
Latest member
jeremy_bp001

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