I am using Microsoft Access 2016 and there is table where I want to count each occurrence of a value in a column grouping by another column. Below is sample data from the table:
| ID | Date | Weekday | Trip_ID | Day | Location |
|---|---|---|---|---|---|
| 1 | 9/11/2022 | Mon | TI06091122 | 1 | Florida |
| 2 | 9/12/2022 | Tue | TI06091122 | 2 | Travel Day |
| 3 | 9/13/2022 | Wed | TI06091122 | 3 | Georgia |
| 4 | 9/14/2022 | Thu | TI06091122 | 4 | South Carolina |
| 5 | 9/15/2022 | Fri | TI06091122 | 5 | North Carolina |
| 6 | 9/16/2022 | Sat | TI06091122 | 6 | Travel Day |
| 7 | 9/17/2022 | Sun | TI06091122 | 7 | Florida |
| 8 | 9/18/2022 | Mon | TI06091822 | 1 | Florida |
| 9 | 9/19/2022 | Tue | TI06091822 | 2 | Travel Day |
| 10 | 9/20/2022 | Wed | TI06091822 | 3 | Travel Day |
| 11 | 9/21/2022 | Thu | TI06091822 | 4 | Travel Day |
| 12 | 9/22/2022 | Fri | TI06091822 | 5 | Colorado |
| 13 | 9/23/2022 | Sat | TI06091822 | 6 | California |
| 14 | 9/24/2022 | Sun | TI06091822 | 7 | Florida |
I want to group the data by Trip_ID and then do a rolling count for each Location. The result I am aiming for is this:
| Trip_ID | Location | RunningCount |
|---|---|---|
| TI06091122 | Florida | 1 |
| TI06091122 | Travel Day | 1 |
| TI06091122 | Georgia | 1 |
| TI06091122 | South Carolina | 1 |
| TI06091122 | North Carolina | 1 |
| TI06091122 | Travel Day | 2 |
| TI06091122 | Florida | 2 |
| TI06091822 | Florida | 1 |
| TI06091822 | Travel Day | 1 |
| TI06091822 | Travel Day | 2 |
| TI06091822 | Travel Day | 3 |
| TI06091822 | Colorado | 1 |
| TI06091822 | California | 1 |
| TI06091822 | New Mexico | 1 |
| TI06091822 | Florida | 2 |
I am able to do a rolling total for the whole table by adding a temporary column equal to 1, and then using DSUM on that column.
DSUM("Temp_Col","Table", "ID<=" & ID) As RunningCount
I believe if I do some sort of subquery per Trip_ID that would do the DSUM I would get what I am looking for, but am unable to determine how to set it up.
Any help would be greatly appreciated. Thank you.