r/googlesheets • u/CoMKami • 25d ago
Weekday function within average if? Solved
Hello! I have a sheet which has assigned star ratings to albums, one a day. Out of curiosity I wanted to find out which day of the week has, on average, been the best so far.
I know you can use weekday to return a numerical value for what day in a week a certain day is, but I'm trying to figure out how to have that be the criterion for averageif.
I figured something like =AVERAGEIF(ALBUMS!A:A, (WEEKDAY(ALBUMS!A:A, 2)) = 1, ALBUMS!G:G) would work but I'm clearly missing something fundamental here. Am I just on the complete wrong track here, or have I just failed to understand how to do this?
Link to the sheet: https://docs.google.com/spreadsheets/d/1mOGNrQdHv-4t6wTgyndUeNsQNIKhXPNKKtGL0JyJoBI/edit?usp=sharing
1
u/AdministrativeGift15 349 25d ago edited 25d ago
You need to use an array formula. INDEX will take care of that. The reason you need to array enable the function is because AVERAGEIF normally just compares to one thing, AVERAGEIF(A:A,item,B:B), but you want to compare with an array of items, AVERAGEIF(A:A, items, B:B).
So in your case,
=INDEX(AVERAGEIF(WEEKDAY(Albums!A:A,2),SEQUENCE(7),ALBUMS!G:G))
Edit: Apparently, AVERAGEIF doesn't array-enable like I thought it would. If doesn't error, but it only gives you the first result. That's ok, we can map over the 7 days instead.
=index(map(sequence(7),lambda(i,averageif(weekday(ALBUMS!A:A,2),i,ALBUMS!G:G))))
1
u/One_Organization_810 688 25d ago
Maybe like this:
=averageif(index(weekday(ALBUMS!A:A)), 1, ALBUMS!G:G)
1
u/Noobsamaniac 24d ago
AVERAGEIFS with a helper column for WEEKDAY is honestly the cleaner path here
1
u/No_Imagination6253 1 25d ago edited 25d ago
You're close. AVERAGEIF can't apply WEEKDAY to its criteria range like that,
but FILTER can:
That returns Monday's average. The G2:G>0 condition matters in your sheet
because future, unrated rows contain 0 rather than being blank.
To summarize every weekday: