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.
 
not yet found a simple solution - sum & count seems to have the same issue as does sumproduct
then its about working out the days in the month - simple to do with =DAY(EOMONTH(B10,0)) works for leap-years and then use indirect to change the range based on that number - but thats a volatile formula and can cause further issues , and seems very complicated for a simple issue - maybe using VBA , not my area

i'll have to see if i can find an alternative , to the problem the formula working out the date is causing ....
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi, you could try like this which shouldn't error when encountering formula produced blanks.

Excel Formula:
=AVERAGE(IF(TEXT($B$28:$B$58,"dddd")=E29,$C$28:$C$58))

Note - it still needs to be array committed on your version of Excel.
 
Upvote 0
Solution
Hi, you could try like this which shouldn't error when encountering formula produced blanks.

Excel Formula:
=AVERAGE(IF(TEXT($B$28:$B$58,"dddd")=E29,$C$28:$C$58))

Note - it still needs to be array committed on your version of Excel.
Oh, great! That's even better and is much neater than my fix :) Thanks again to both of you
 
Upvote 0
Hi,

Hoping to revisit this. I want to introduce a formula to the "Ridership by Day" table this formula pulls from that effectively removes that day from the average calculations found in the "Ridership by Day Summary" table if we cancel service for that day. Put another way, a canceled Monday would result in 3 Mondays being used in the calculation instead of 4. One thing I've tried is having the formula in "Ridership by Day" display a blank ("") whenever that day is canceled. This is now causing an issue with my SUMPRODUCT formulas in the "Ridership by Day Summary" table, causing them to produce VALUE errors. Not sure why this wasn't happening before, but it's the same issue that was occurring with the Average IF formula above (I think!).

Eastern Ridership Report Template-v3.4 - TEST.xlsx
BCD
25Ridership by Day Summary
26Day of WeekTotal/DayAverage/Day
27Monday#VALUE!0.0
28Tuesday#VALUE!0.0
29Wednesday#VALUE!0.0
30Thursday#VALUE!0.0
31Friday#VALUE!0.0
32Saturday#VALUE!0.0
33Sunday#VALUE!0.0
34
35
36Ridership by Day
378/1/23 
388/2/230
398/3/230
408/4/230
418/5/230
428/6/230
438/7/230
448/8/230
458/9/230
468/10/230
478/11/230
488/12/230
498/13/230
508/14/230
518/15/230
528/16/230
538/17/230
548/18/230
558/19/230
568/20/230
578/21/230
588/22/230
598/23/230
608/24/230
618/25/230
628/26/230
638/27/230
648/28/230
658/29/230
668/30/230
678/31/230
680
Summary
Cell Formulas
RangeFormula
C27:C33C27=SUMPRODUCT((TEXT(B$37:B$67, "ddddddddd")=B27)*((C$37:C$67)))
D27:D33D27=AVERAGE(IF(TEXT($B$37:$B$67,"dddd")=B27,$C$37:$C$67))
B37B37=B10
B38:B65B38=IF(MONTH(B37+1)=MONTH($B$10),B37+1,(""))
B66B66=IF(MONTH(B64+2)=MONTH($B$10),B64+2,(""))
B67B67=IF(MONTH(B64+3)=MONTH($B$10),B64+3,(""))
C37C37=IF((AND('BND to ONT'!B2=TRUE,'ONT to BND'!B2=TRUE)),"",(SUM('BND to ONT'!N2:N3,'ONT to BND'!N2:N3)))
C38C38=SUM('BND to ONT'!N5:N6,'ONT to BND'!N5:N6)
C39C39=SUM('BND to ONT'!N8:N9,'ONT to BND'!N8:N9)
C40C40=SUM('BND to ONT'!N11:N12,'ONT to BND'!N11:N12)
C41C41=SUM('BND to ONT'!N14:N15,'ONT to BND'!N14:N15)
C42C42=SUM('BND to ONT'!N17:N18,'ONT to BND'!N17:N18)
C43C43=SUM('BND to ONT'!N20:N21,'ONT to BND'!N20:N21)
C44C44=SUM('BND to ONT'!N23:N24,'ONT to BND'!N23:N24)
C45C45=SUM('BND to ONT'!N26:N27,'ONT to BND'!N26:N27)
C46C46=SUM('BND to ONT'!N29:N30,'ONT to BND'!N29:N30)
C47C47=SUM('BND to ONT'!N32:N33,'ONT to BND'!N32:N33)
C48C48=SUM('BND to ONT'!N35:N36,'ONT to BND'!N35:N36)
C49C49=SUM('BND to ONT'!N38:N39,'ONT to BND'!N38:N39)
C50C50=SUM('BND to ONT'!N41:N42,'ONT to BND'!N41:N42)
C51C51=SUM('BND to ONT'!N44:N45,'ONT to BND'!N44:N45)
C52C52=SUM('BND to ONT'!N47:N48,'ONT to BND'!N47:N48)
C53C53=SUM('BND to ONT'!N50:N51,'ONT to BND'!N50:N51)
C54C54=SUM('BND to ONT'!N53:N54,'ONT to BND'!N53:N54)
C55C55=SUM('BND to ONT'!N56:N57,'ONT to BND'!N56:N57)
C56C56=SUM('BND to ONT'!N59:N60,'ONT to BND'!N59:N60)
C57C57=SUM('BND to ONT'!N62:N63,'ONT to BND'!N62:N63)
C58C58=SUM('BND to ONT'!N65:N66,'ONT to BND'!N65:N66)
C59C59=SUM('BND to ONT'!N68:N69,'ONT to BND'!N68:N69)
C60C60=SUM('BND to ONT'!N71:N72,'ONT to BND'!N71:N72)
C61C61=SUM('BND to ONT'!N74:N75,'ONT to BND'!N74:N75)
C62C62=SUM('BND to ONT'!N77:N78,'ONT to BND'!N77:N78)
C63C63=SUM('BND to ONT'!N80:N81,'ONT to BND'!N80:N81)
C64C64=SUM('BND to ONT'!N83:N84,'ONT to BND'!N83:N84)
C65C65=SUM('BND to ONT'!N86:N87,'ONT to BND'!N86:N87)
C66C66=SUM('BND to ONT'!N89:N90,'ONT to BND'!N89:N90)
C67C67=SUM('BND to ONT'!N92:N93,'ONT to BND'!N92:N93)
C68C68=SUM(C37:C67)
Press CTRL+SHIFT+ENTER to enter array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C37:C67Cell Value<1textNO


Let me know if this makes sense, if not I'm happy to answer any questions.

Thanks!
 
Upvote 0
Hi, you could try changing your SUMPRODUCT() formula to this:

Excel Formula:
=SUMPRODUCT(--(TEXT(B$37:B$67,"dddd")=B27),C$37:C$67)
 
Upvote 0
Hi, you could try changing your SUMPRODUCT() formula to this:

Excel Formula:
=SUMPRODUCT(--(TEXT(B$37:B$67,"dddd")=B27),C$37:C$67)
Wow, a very simple solution. It looks like it's working. Thank you again so much! I don't recall why I had the TEXT function set to look for "ddddddddd" instead of "dddd". Can you please tell me what purpose the "--" serves before TEXT?
 
Upvote 0
what purpose the "--" serves before TEXT?
Hi, It performs a mathematical operation on the TRUE/FALSE values returned by the logical test (TEXT(B$37:B$67,"dddd")=B27) which coerces the FALSE values to a 0 and the TRUE values to a 1
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

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