I have a shared activity log of bike rides in Google Sheets that looks like:
[A] Date | [B] Name | [C] Miles |
---|---|---|
1 Nov 2, 2022 | Joe | 2.1 |
[2] Nov 2, 2022 | Ray | 1.5 |
[3] Nov 3, 2022 | Ray | 3.1 |
[4] Nov 4, 2022 | Joe | 2.9 |
[5] Nov 4, 2022 | Joe | 2.2 |
This will run the whole month. On another sheet I'd like to show the participants, their active days in the week and the total distance they rode.
Leaderboard for Nov 1 - 5 | [A] Name | [B] Active Days | [C] Distance | | --- | ----------- | -------- | | 1 Joe | =COUNTIFS(...) | =SUMIFS(...) | | [2] Ray | =COUNTIFS(...) | =SUMIFS(...) |
I created COUNTIFS and SUMIFS like the following:
Cell B2 for Joe =COUNTIFS(B:B,A1,A:A,">="&DATE(2022,11,1),A:A,"<="&DATE(2022,11,5))
Cell C2 for Joe =SUMIFS(C:C,B:B,A1,A:A,">="&DATE(2022,11,1),A:A,"<="&DATE(2022,11,5))
This worked well until I had the situation where someone did two activities in a day, as happens with Joe on Nov 4 (rows 4 and 5). The total miles is correct but I need to have the COUNTIFS take into account unique dates. My formula would report 3 when the answer should be 2.
A live Google Sheet recreating the above is here.
I've played with:
- FILTER:
=FILTER(A:C, B:B = "Joe", A:A >=DATE(2022,11,1), A:A <= DATE(2022,11,5))
- DCOUNTA:
=DCOUNTA(A:C,"Date",{{"Name";"Joe"},{"Date";">=Nov 1, 2022"},{"Date";"<=Nov 5, 2022"}})
- QUERY:
=COUNT(UNIQUE(QUERY(Log!A:C, "select A where B = 'Joe' and A >=date'2022-11-1' and A <=date'2022-11-05'")))
The QUERY above seems to work feels a little wonky. I'm wondering if there are suggestions at better ways to go about this?