Forum Academy Marketplace Showcase Pricing Features

Calculating SUM of repeating inputted values

I currently have a page where a user can input a tenants apartment number, the weight of their laundry bag, and the price they pay. Once the information is submitted it gets stored in the data base.

I want to create a page that sums up the totals based on the tenant’s usage. I would also like that everything displays in ascending order. So if i inputted data on tenant 1A who’s bag weighed 10 pounds and cost $15 dollars. And then I inputted data on tenant 1B who’s bag weighed 20 pounds and cost $30 dollars. And then i inputted data on tenant 1A who’s bag weighed 15 pounds and cost $20 dollars. Then on the new page it would display 1A and then 1B. In 1A it would display the total weight as 25 pounds and the total cost would be $35. On the next line there would be tenant 1B with a total weight of 20 pounds and a total cost of $30 dollars.

Essentially I need a way to check the static apartment number, go to the data base, find all of the data entries that match the static apartment number. And then add up the corresponding data points for the requested fields.

Help would be great since I’ve been trying to figure this out for a while. Thank you!

Hello! What does your database structure look like? There are many ways to achieve what you want, but it all comes down to what your database looks like.

Let’s imagine that your database looks as follows, what you want to achieve is relatively straightforward:

  1. You have a data type called “Tenant” that has the following fields:
  • Apartment number (type: text)
  • Laundry errands (type: list of Laundry errands)
  1. The Laundry errand data type looks something like this:
  • Weight in Pounds (type: number)
  • Cost in Dollars (type: number)

Every time a tenant orders a Laundry errand in your app, you can create a new “Laundry errand” and add it to the Tenant’s list of Laundry errands.

After that, it’s just a matter of listing all Laundry errands that belong to a specific tenant. To show the total weight and cost per tenant, you can use “each item’s Weight in Pounds:Sum” to get the total weight, and the corresponding operation for the Cost in Dollars.

If you’ll do this search operation for a big record of tenants and/or tenants that have done lots of laundries, you could also consider storing the total weight and total cost as a field on the tenant to reduce the search time (and WU usage).

Hope this guides you in the right direction :slight_smile:

Does this make sense?

Interesting. How would this work for multiple tenants though? How would I be able to specify which data is calculated for the specific tenant that I am displaying? Currently, I have a data type labeled 215w101. In the data type i have the fields “Tenant Apartment”, “Bag Weight”, and “Cost”. I have an input page where I can go to submit the laundry bags as they come, adding the customers apartment number, bag weight, and bag cost. This information gets logged into the data base once submitted. There are multiple customers in the property and there will be multiple laundry entries for each tenant.

The concept is to ultimately create a page that would display the total usage for each apartment. So it will show the apartment number, the total bag weight that they have provided, and the total cost for all of the bags they’ve ever submitted. For that to work Id need there to be a way to go to the database 215w101, and calculate the total’s for bag weight and cost price for each time that that specific tenant has had a laundry entry. So i can not generate the sum for the field bag weight within the data type 215w101 because that will provide me with the total bag weight for all of the tenant entries.

Im not sure if that makes sense. I will provide a figma-generated example of what I’d ultimately want to create for the totals page. I can also provide photos of my data base or input page if needed. Thank you so much for the help, it is really appreciated :slight_smile:

Assuming that “215w101” is the name of the apartment building, you can achieve what you want with a nested repeating group (one RG inside of another RG).

Page Type: Apartment Building (or whatever the data type is called)

Outer RG: Do a search for Page’s Apartment Building’s Tenants (assuming that Apartment Building has a list of Tenants as a Field)

Inner RG: Do a search for Current Cell’s List of Laundry Errands (and from here you can follow the steps outlined in my first post to get the weight and revenue). Note that Current Cell = The outer RG’s current Tenant (e.g. “1A”).

Does this make sense? :smiley: