How to Count Records by the Week they were Created?
Options
![Karl Larson](https://us.v-cdn.net/6037124/user_avatars/2042798.jpg)
Karl Larson
Member ✭
Overall ObjectiveUsers set a target for the number of times they want to workout per week and for how long (e.g. 4 workouts per week for 20 out of 26 weeks). Every time they workout, the post a photo to prove they worked out.
To see if they achieved their target, I need to count the number of workouts every week and compare that to their weekly goal. Then, update the total number of weeks they've reached that goal vs. did not and compare it to their overall target.
DetailsHere is a screenshot of the goals table. [CleanShot 2021-11-05 at 11.21.29@2x.jpg]
I've created a function that gets the id and created time of all a user's photos.
[CleanShot 2021-11-05 at 11.22.50@2x.jpg]
Now, I'm trying to figure out how to get the week from the photo's timestamp, and then update the done_workout_weeks and done_rest_weeks (I'm ignoring done_light_weeks for now).
Any ideas? Thanks in advance for your advice.
To see if they achieved their target, I need to count the number of workouts every week and compare that to their weekly goal. Then, update the total number of weeks they've reached that goal vs. did not and compare it to their overall target.
DetailsHere is a screenshot of the goals table. [CleanShot 2021-11-05 at 11.21.29@2x.jpg]
I've created a function that gets the id and created time of all a user's photos.
[CleanShot 2021-11-05 at 11.22.50@2x.jpg]
Now, I'm trying to figure out how to get the week from the photo's timestamp, and then update the done_workout_weeks and done_rest_weeks (I'm ignoring done_light_weeks for now).
Any ideas? Thanks in advance for your advice.
Comments
-
Hey - you should be able to accomplish this with the aggregator return type on your query all records function...
Group by: user_id and
created_at (filter: timestamp_week)
Aggregate by:
user_id (or other field that makes sense)
Aggregator: count
[Screenshot_2021-11-05_19-19-56.png]
If you want it to just be an individual user, then I would turn on authentication on and first do a by custom query where photos.user_id = auth ID.... and then you also don't need to group by user id by doing that.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback