Best approach for a looping count?

I’m a relatively new Bubbler; I’ve been at it for a few months, taking courses and lurking here. I’ve finally come across a question I haven’t been able to find an answer to…

I have a database table (pasted below) that is tracking the number of questions and answers asked in a survey for a project. Each survey will have an undefined number of recipients and questions. Recipients can answer any number of the questions asked. It’s not mandatory that they answer all questions. However, a survey is only considered “complete” when all recipients have completed ALL questions. This is what I’m trying to count.

I tried using backend workflows to do this, but couldn’t get past the fact that I’m not actually making changes to any things, I’m just trying to count them.

I’ve almost settled on having to write this up in JavaScript but I keep thinking there’s gotta be a way to do this in Bubble natively.

(For this sample screen cap, all surveys belong to the same project, and only survey vPx… is “complete” since its two recipient companies have answered all questions.)

So to recap quickly:

  1. A project can have many surveys.
  2. A survey has N questions
  3. A survey has X recipients
  4. Recipients can answer any number of questions
  5. A survey is only considered “complete” when all questions are answered by all recipients.

For any given project, I need to be able to count how many surveys are complete.

What am I missing here…? Any guidance is most appreciated. Thank you!

You are not missing anything. It is complicated though. You should do things step by step to understand the logic. I have the following repeating group generated for your data:

Now, let’s dive into how each column(?) and the final text field is calculated.
I named the main data type as Project, but it doesn’t matter of course.

The repeating group is just displaying a list of unique survey IDs in this project. It is just text:

Finding the count of this survey in this project:

Total answers received in all instances of this survey. Simply the sum of each answer count of this survey:

Total answers must be equal to the number of surveys multiplied by question count of any of these surveys. (Same survey IDs have same question counts.)

Then, checking for completeness is just a matter of checking if the total answer count is equal to question count * survey count.
image

Above was if you want to make a table out of it.
If you want a single number, I could do it as well:

The important thing in this formula is the filter. Filter is doing the same thing as the last column in the table and filtering out the NOs.

1 Like

This is fantastic. I used a similar solution on another set of dashboard views, and have been so focused on looping I never even considered this. Another set of eyes can be so key! Thank you so much for taking the time with such a detailed response. You’ve helped salvage my entire week!