Averaging weekday totals in excel

iclancy

New Member
Joined
Mar 12, 2021
Messages
17
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I'd like to find average ridership counts by day from my table. This table updates based on the current month so I need a formula that can keep up. I have researched several different formulas to do this, but each one I've found ends up counting all of the zeros from the "Ridership by Day" table in the average formula, instead of just the total number of that day. For example, the formula in the below screenshot ends up dividing the total counts for Mondays for the month (17) by 31, so 17/31 = 0.6129. How can I ensure that the formula would correctly divide by the total number of Mondays (17/4 in the example case)?

Here are a couple of the formulas I've tried:

=AVERAGE(IF(WEEKDAY(B28)=WEEKDAY($B$28:$B$58),$C$28:$C$58))
=AVERAGE(IF(DAY(B28:B58)=1,C28:C58))

I've also tried referencing column E for the "serial number" argument in the WEEKDAY function, but that returns a #VALUE! error.

1662762256167.png


Thanks in advance for your help. Let me know if you need me to provide more information.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
=AVERAGE(IF(WEEKDAY($B$28:$B$58,2)=1,$C$28:$C$58))

if you put , 1 ,2 , 3 4 etc against the days - then you can reference the cell

Book1
ABCDEFG
1
2Tue1/4/2211Monday12
3Wed1/5/22142Tuesday3
4Thu1/6/223Wednesday14
5Fri1/7/224Thursday0
6Wed1/5/22145Friday0
7Thu1/6/226Saturday0
8Fri1/7/227Sunday0
9Sat1/8/22
10Sun1/9/22
11Mon1/10/2212
12Tue1/11/225
13Wed1/12/2214
14Thu1/13/22
15Fri1/14/22
16
Sheet1
Cell Formulas
RangeFormula
G2:G8G2=AVERAGE(IF(WEEKDAY($B$2:$B$15,2)=E2,$C$2:$C$15))


enter as an array formula
Shift + Ctrl + Enter keys together


Note: Images are difficult to see , and also requires that I input all the data myself, which is very time consuming.

A SMALL sample spreadsheet, around 10-20 rows, would help a lot here, with all sensitive data removed, and expected results mocked up and manually entered, with a few notes of explanation.

MrExcel has a tool called “XL2BB” that lets you post samples of your data and will allow us to copy/paste your sample data into our Excel spreadsheets, saving a lot of time.

You can also test to see if it works ok, in the "Test Here" forum.

OR if you cannot get XL2BB to work, or have restrictions on your PC , then put the sample spreadsheet onto a share
I only tend to goto OneDrive, Dropbox or google docs , as I'm never certain of other random share sites and possible virus.
Please make sure you have a representative data sample and also that the data has been desensitised, remember this site is open to anyone with internet access to see - so any sensitive / personal data should be removed
 
Upvote 0
Thanks for the tip. Here's a mini-sheet. The end result I am trying to get is having the "Avg" column display the average ridership by day of the week, pulled from the "Ridership by Day" table, similar to how the "Total" column next to it displays the total ridership by day using the SUMPRODUCT function. Ideally I'm looking for a way to do this without adding extra columns, if possible.

In the below sheet, the correct average of 7 is manually entered for Monday; the other formulas I've tried are in the Tuesday and Wednesday cells below it.

Cell Formulas
RangeFormula
B11B11=DAY(DATE(YEAR(B10),MONTH(B10)+1,1)-1)
G16G16=AVERAGE(IF(DAY(B15:B45)=1,C15:C45))
G17G17=AVERAGE(IF(WEEKDAY(E17)=WEEKDAY($B$15:$B$45),$C$15:$C$45))
C15C15=SUM('BND to ONT'!N2:N3,'ONT to BND'!N2:N3)
C16C16=SUM('BND to ONT'!N5:N6,'ONT to BND'!N5:N6)
C17C17=SUM('BND to ONT'!N8:N9,'ONT to BND'!N8:N9)
C18C18=SUM('BND to ONT'!N11:N12,'ONT to BND'!N11:N12)
C19C19=SUM('BND to ONT'!N14:N15,'ONT to BND'!N14:N15)
F15:F21F15=SUMPRODUCT((TEXT(B$15:B$45, "ddddddddd")=E15)*((C$15:C$45)))
C21C21=SUM('BND to ONT'!N20:N21,'ONT to BND'!N20:N21)
C22C22=SUM('BND to ONT'!N23:N24,'ONT to BND'!N23:N24)
C23C23=SUM('BND to ONT'!N26:N27,'ONT to BND'!N26:N27)
C24C24=SUM('BND to ONT'!N29:N30,'ONT to BND'!N29:N30)
C25C25=SUM('BND to ONT'!N32:N33,'ONT to BND'!N32:N33)
C26C26=SUM('BND to ONT'!N35:N36,'ONT to BND'!N35:N36)
C28C28=SUM('BND to ONT'!N41:N42,'ONT to BND'!N41:N42)
C29C29=SUM('BND to ONT'!N44:N45,'ONT to BND'!N44:N45)
C30C30=SUM('BND to ONT'!N47:N48,'ONT to BND'!N47:N48)
C31C31=SUM('BND to ONT'!N50:N51,'ONT to BND'!N50:N51)
C32C32=SUM('BND to ONT'!N53:N54,'ONT to BND'!N53:N54)
B15B15=B10
B16:B43B16=IF(MONTH(B15+1)=MONTH($B$10),B15+1,(""))
B44B44=IF(MONTH(B42+2)=MONTH($B$10),B42+2,(""))
B45B45=IF(MONTH(B42+3)=MONTH($B$10),B42+3,(""))
C35C35=SUM('BND to ONT'!N62:N63,'ONT to BND'!N62:N63)
C36C36=SUM('BND to ONT'!N65:N66,'ONT to BND'!N65:N66)
C37C37=SUM('BND to ONT'!N68:N69,'ONT to BND'!N68:N69)
C38C38=SUM('BND to ONT'!N71:N72,'ONT to BND'!N71:N72)
C39C39=SUM('BND to ONT'!N74:N75,'ONT to BND'!N74:N75)
C40C40=SUM('BND to ONT'!N77:N78,'ONT to BND'!N77:N78)
C41C41=SUM('BND to ONT'!N80:N81,'ONT to BND'!N80:N81)
C42C42=SUM('BND to ONT'!N83:N84,'ONT to BND'!N83:N84)
C43C43=SUM('BND to ONT'!N86:N87,'ONT to BND'!N86:N87)
C44C44=SUM('BND to ONT'!N89:N90,'ONT to BND'!N89:N90)
C45C45=SUM('BND to ONT'!N92:N93,'ONT to BND'!N92:N93)
C46C46=SUM(C15:C45)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B15:B46Expression=$B15="Saturday, July 3, 2021"textNO
C15:C45Cell Value<1textNO
C19Expression=OR(#REF!=7,#REF!=1)textNO
C20Expression=OR(#REF!=7,#REF!=1)textNO
C21Expression=OR(#REF!=7,#REF!=1)textNO
C22Expression=OR(#REF!=7,#REF!=1)textNO
C23Expression=OR(#REF!=7,#REF!=1)textNO


I hope this helps.
 
Upvote 0
how about
=AVERAGE(IF(WEEKDAY($B$15:$B$45,2)=MATCH(E15,{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),$C$15:$C$45))


Book1
ABCDEFG
6Version3.1
7
8
9
10Invoice Month (mm/dd/yyyy)7/1/21
11Service Days this Month31
12
13Ridership by Day
14DayRidershipTotalAvg
157/1/211Monday205
167/2/212Tuesday246
177/3/213Wednesday287
187/4/214Thursday51
197/5/215Friday102
207/6/216Saturday153
217/7/217Sunday164
227/8/211
237/9/212
247/10/213
257/11/214
267/12/215
277/13/216
287/14/217
297/15/211
307/16/212
317/17/213
327/18/214
337/19/215
347/20/216
357/21/217
367/22/211
377/23/212
387/24/213
397/25/214
407/26/215
417/27/216
427/28/217
437/29/211
447/30/212
457/31/213
Sheet1
Cell Formulas
RangeFormula
B11B11=DAY(DATE(YEAR(B10),MONTH(B10)+1,1)-1)
F15:F21F15=SUMPRODUCT((TEXT(B$15:B$45, "ddddddddd")=E15)*((C$15:C$45)))
G15:G21G15=AVERAGE(IF(WEEKDAY($B$15:$B$45,2)=MATCH(E15,{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),$C$15:$C$45))
B15B15=B10
B16:B43B16=IF(MONTH(B15+1)=MONTH($B$10),B15+1,(""))
B44B44=IF(MONTH(B42+2)=MONTH($B$10),B42+2,(""))
B45B45=IF(MONTH(B42+3)=MONTH($B$10),B42+3,(""))
 
Upvote 0
Thanks! I'm not sure why, but the formula is not working for me when I plug it in to my spreadsheet. It still returns a 0 for Monday and all the other days of the week. I thought it might have something to do with the way my dates are displayed in the ridership table, so I tried changing them to Short Date format to match your table but still got the same result. Any idea as to why the same formula wouldn't work for my sheet?
 
Upvote 0
i notice you are using 2016 - is that the case

its an array formula so it will need to be entered using
Ctrl+Shift+Enter
and then you should see
{=AVERAGE(IF(WEEKDAY($B$15:$B$45,2)=MATCH(E15,{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),$C$15:$C$45))}
 
Upvote 0
Hi,

I've noticed another (hopefully!) minor issue with the new averaging formula above that I am having trouble fixing. I mentioned above that the "Ridership by Day" table updates based on the current month. When changed to a month with 30 days, the averaging formulas for all days in the "Average" column return #VALUE! errors, due to the fact that the last day's cell, B58, now displays as a blank because of previous formatting I implemented for neatness (without this formatting, the cell displays the first day of the following month, which is undesired). When evaluating the WEEKDAY function in the averaging formula, it encounters the blank cell with no date and doesn't know what to do with it. See cell B58 in the mini-sheet:

Cell Formulas
RangeFormula
F29:F35F29=SUMPRODUCT((TEXT(B$28:B$58, "ddddddddd")=E29)*((C$28:C$58)))
G29:G35G29=IF(B58="",AVERAGE(IF(WEEKDAY($B$28:$B$57,2)=MATCH(E29,{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),$C$28:$C$57)),AVERAGE(IF(WEEKDAY($B$28:$B$58,2)=MATCH(E29,{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),$C$28:$C$58)))
B28B28=B10
B29:B56B29=IF(MONTH(B28+1)=MONTH($B$10),B28+1,(""))
B57B57=IF(MONTH(B55+2)=MONTH($B$10),B55+2,(""))
B58B58=IF(MONTH(B55+3)=MONTH($B$10),B55+3,(""))
C28C28=SUM('BND to ONT'!N2:N3,'ONT to BND'!N2:N3)
C29C29=SUM('BND to ONT'!N5:N6,'ONT to BND'!N5:N6)
C30C30=SUM('BND to ONT'!N8:N9,'ONT to BND'!N8:N9)
C31C31=SUM('BND to ONT'!N11:N12,'ONT to BND'!N11:N12)
C32C32=SUM('BND to ONT'!N14:N15,'ONT to BND'!N14:N15)
C33C33=SUM('BND to ONT'!N17:N18,'ONT to BND'!N17:N18)
C34C34=SUM('BND to ONT'!N20:N21,'ONT to BND'!N20:N21)
C35C35=SUM('BND to ONT'!N23:N24,'ONT to BND'!N23:N24)
C36C36=SUM('BND to ONT'!N26:N27,'ONT to BND'!N26:N27)
C37C37=SUM('BND to ONT'!N29:N30,'ONT to BND'!N29:N30)
C38C38=SUM('BND to ONT'!N32:N33,'ONT to BND'!N32:N33)
C39C39=SUM('BND to ONT'!N35:N36,'ONT to BND'!N35:N36)
C40C40=SUM('BND to ONT'!N38:N39,'ONT to BND'!N38:N39)
C41C41=SUM('BND to ONT'!N41:N42,'ONT to BND'!N41:N42)
C42C42=SUM('BND to ONT'!N44:N45,'ONT to BND'!N44:N45)
C43C43=SUM('BND to ONT'!N47:N48,'ONT to BND'!N47:N48)
C44C44=SUM('BND to ONT'!N50:N51,'ONT to BND'!N50:N51)
C45C45=SUM('BND to ONT'!N53:N54,'ONT to BND'!N53:N54)
C46C46=SUM('BND to ONT'!N56:N57,'ONT to BND'!N56:N57)
C47C47=SUM('BND to ONT'!N59:N60,'ONT to BND'!N59:N60)
C48C48=SUM('BND to ONT'!N62:N63,'ONT to BND'!N62:N63)
C49C49=SUM('BND to ONT'!N65:N66,'ONT to BND'!N65:N66)
C50C50=SUM('BND to ONT'!N68:N69,'ONT to BND'!N68:N69)
C51C51=SUM('BND to ONT'!N71:N72,'ONT to BND'!N71:N72)
C52C52=SUM('BND to ONT'!N74:N75,'ONT to BND'!N74:N75)
C53C53=SUM('BND to ONT'!N77:N78,'ONT to BND'!N77:N78)
C54C54=SUM('BND to ONT'!N80:N81,'ONT to BND'!N80:N81)
C55C55=SUM('BND to ONT'!N83:N84,'ONT to BND'!N83:N84)
C56C56=SUM('BND to ONT'!N86:N87,'ONT to BND'!N86:N87)
C57C57=SUM('BND to ONT'!N89:N90,'ONT to BND'!N89:N90)
C58C58=SUM('BND to ONT'!N92:N93,'ONT to BND'!N92:N93)
C59C59=SUM(C28:C58)
Press CTRL+SHIFT+ENTER to enter array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C28:C58Cell Value<1textNO
B28:C58Expression=(TEXT($B28:$B58,"ddddddddd")=$E$35)textNO
B28:C58Expression=(TEXT($B28:$B58,"ddddddddd")=$E$34)textNO


I thought of a work-around using a nested IF statement which is currently being used in cells G29:G35. It works, but it gets a lot messier when trying to do the same for the month of February, as well as a February which falls on a leap year (29 days).
So....my question is, is there a neater way to make the existing formula {=AVERAGE(IF(WEEKDAY($B$28:$B$58,2)=MATCH(E15,{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),$C$15:$C$45))} first check to see whether there are blank cells for B56, B57 and B58, and then decide whether or not to use them in the WEEKDAY function in the formula?
 
Upvote 0
it will handle blank cells ?
but your cells are not blank as they have a formula in

its more to do with the way the dates are created

so weekday() even if the formula returns "" will still give a Value error -

which is what the problem is - looked into a couple of ways to solve - but so far no luck - i'm sure there is a simple fix
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,867
Members
449,192
Latest member
MoonDancer

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