Last 30 Days Calculation

So I have an app where users visit locations. I’d like to add a summary banner with the number of visits in the last 30 days. I’ve only be able to list the Logged in User’s total visit. Any recommendations on listing total visits in the last 30 days?

1 Like

Just play around with the date & time property and count.

day 1 - n count
day 2 - n count.

Day 30 - Total n counts.

So I have a business listings app. I have a collection called Page Views, and every time a user visits a listing’s details page, a countdown triggers, which creates a Page Views record. So in addition to the date created field, I have an expiration date field that’s 30 days away from the created date. On my listing’s admin analytics page, I have another countdown that I converted to a list. This “list” is of any Page View records with an expiration date that has passed. Once the countdown reaches 0, it deletes said records. So then, I can always sum the total number of live Page View records, since they’ll always be within 30 days.

It sounds like you’d like to do it for users, rather than a listing or location. The same concept can be achieved by linking the Page Views collection to your Users collection instead. The key is making that countdown list trigger/occur before the user can view the desired 30-days total. For instance, if the countdown occurs on the same page as where you’re showing the number, it’ll show the initial number and decrease in real time as the expired list is deleted. I hope it all makes sense.

I’m sure there may be an easier way, but that’s how I managed to do it.


Thanks for the insights. See what I have below. I just have magic text and want the count to be generated but don’t have a way to calculate the actual number. Where in my app would I do this?

@Sutter_j44 - Thanks for the details but I don’t want my records to disappear and hoping there’s an easier way.

@endieumunna - When you say “Just play around with the date & time property and count” what does that mean exactly?

@Emeka So right now, it looks like your “Visit count” magic text is just a single field within a collection, like a user’s name or phone number within your main Users collection. Am I correct on that? Are you using a formula or trigger that just updates a number every time a visit occurs? If you want to somehow calculate a number that’s based on a specific amount of days, you’ll need to count the total number of records in a separate collection, where you judge a created date vs another date. That’s what endieumunna meant by playing around with date and time properties. You say you don’t want to delete any records. Keep in mind, in the example I explained above, those records are only Page View records…not User records, not Listings records, etc. It only serves the purpose of helping me get a 30-day count. But if you go the route of using a separate collection just for view records and you don’t want to delete them, perhaps you can create a formula that only counts the number of view records from “today-30” or something. I’ll play around with my setup and see if I can come up with something different than my auto-delete example.

Ok, so I just did some experimenting with my current set up. If you scroll up, you’ll see I have a separate collection “Page Views” that’s connected to my “Listings” collection. Each time a user visits a page, a new record is created in the “Page Views” collection. I went a created a magic text input and counted the total number of Page View records for a specific listing, but only those records where the date created was between 30 days ago and the start of today. This method bypasses having to delete anything, but keep in that something like a collection solely dedicated to page views can stack up quickly, especially if you have a lot of users. I’d suggest still going with an auto-delete method, so you prevent too many records.

Thanks a ton! I should have tried this haha. I went a slightly different route given the “Is Between” setting wasn’t working for me. I used is after instead.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.