I need help on how to count how many records in one table are related to a record in another table

I’m using WeWeb tables and want to count how many records in one table are related to a record in another table.

Example:

  • Table A (parent)

  • Table B (child with a relation field to A)

For a given record in Table A, I want to display how many related records exist in Table B.

What is the correct way in WeWeb to:

  • Filter one table based on a relation field

  • Count the matching records

Should this be done with a formula, rollupSum, or another method?

Hey @Danny!
You can do this by creating a View on the child table and exposing the relational fields you need to count the related records, like this:

From there, bind that view to your frontend and use a combination of length and filterByKey to count the matching records:

Does that help?

Yes, this helped me a lot. I have a question though—how am I supposed to know how to use formula syntax like this in the future?

I wouldn’t have figured out to write it the way you showed (like Projects[name]). Is there a specific way to learn this? I haven’t been able to find anything online that explains WeWeb formulas at this level.

Is there a name for the type of formula syntax WeWeb uses so I can study it?

WeWeb’s documentation explains the operators, but it doesn’t show how to structure formulas like this. I’ve tried using variables instead, but nothing worked except typing it exactly the way you showed.

I really want to learn WeWeb formulas so I’m not relying on the community every time I get stuck on something like this.

Thanks again for your help — I did get it working, but I want to clarify something.

The way I originally set it up works, but I’m realizing it’s not scalable for a SaaS app because it’s hard-coded and not dynamic. It relies on fixed values (like filtering by active), which means the result is the same everywhere and doesn’t adapt per record.

As more records or relationships are added, that approach would require creating separate filters or views, which isn’t maintainable long-term.

From what I understand now, the better approach is to use something dynamic (like referencing the current item in the list), so each record calculates its own result based on its relationship data.

I’d recommend going through the variables video and the formula documentation first. Each formula documentation includes an example, which should help you better understand how and when to use it.


After that, if you’re stuck on a specific formula, you can describe the behavior you’re trying to achieve to WeWeb AI, along with the data you’re working with, and ask for a setup recommendation or help setting it up directly.

Does that help?

In my example, I used the same view to calculate the number of tasks associated with different projects.

For Project B and Project C, I only changed the value being used in the frontend formula to Project B and Project C respectively:

but how can this be done dynamically in a saas app where users create there own project names?

That is doable too :slight_smile:

A couple of questions first: Are projects tied to users? Can users have more than one project?

my scenario would be super admins being a business owner. Super admins can create custom named “Circles”. Circles can have clients added to them as a way to categorize the clients.