Create Variable To Aggregate Data

Hello beautiful Bubblers!

New to Bubble but wondering if I could create variable = data y + data x etc.

Context: I’m building an online learning patlform

Right now I have fields for every lesson a student completes:

L1 = 1, when student completes lesson 1
L2 = 2, when students completes lesson 2
Etc.

I want to create a variable called Completed Lessons = Sum of L1 + L2 + … + Ln

How would I create a variable like this?

Thank you in advance! :grin:

Best,

Andy Anderson Andreeson Horowitz IV

Yes, it’s possible to do that. It’s just a text field. Where you store the text field could be:

  • in the database
  • on a state on the page
  • on the URL

I’m guessing on the database is the best place in your case.


ps: Killer signature.

1 Like

@rico.trevisan Thank you so much!

Great to know but still not sure how exactly I do it eek

For example I just made a cheeky new variable called M1

image

But how do I set M1 = [stuff] there doesn’t seem to be the option from the Data tab…

You do not need a separate field for each lesson.

Create a field on the User called Completed Lessons with type being “Lessons” and specify this field is a list.

When user completes a lesson, run a workflow to “change a thing” → change current Users → Completed Lessons add This Lesson.

https://manual.bubble.io/core-resources/actions/data-things

Rob

@andrewmitson94 I suggest you try what @robhblake mentioned but instead of making the field a list, you can simply add +1 to the number in the field. For instance, if a user is an L2 level, according to your taxonomy, the corresponding value of the data type would be “2” (number field) if they complete lesson 2. If they complete lesson 3, run a workflow that simply takes thelesson number field (in this case “2”) and do “+1”. This way you will always end up with a single number in the data field, not multiple.

1 Like

Hey guys - any chance you one of your wonderful Bubblers could help me with this?

Happy to feature you in Bubble’s Build An App in 30 Day Challenge (currently filming it, updating my progress every day!)

Thanks so much in advance :heart:

Andrew Andreeson Horowitz IV

Hey Andy

I think what’s going on is that your M1 variable is only being set once - i.e. “on page load” on the “modules” page. Since you have the progress bar in the individual “lesson” pages too, you will need to have the same action on page load in each of those pages. I didn’t see the editor for the “module1_lesson1” page but my guess is you’re not running the “set value of M1” workflow on page load there (and any other page that uses the progress bar).

Did that do the trick?

Let us know your YouTube channel!

Cheers
Rob.

OH DAMN! @robhblake yes that makes hella sense

Is there an easier way than setting “M1 = …” on every page load? For example, is there a way to just permanently set M1 = … + … etc. ?

Will be posted on the Bubble YT channel in May (I hope!) Will message you when it’s out too - along with everyone who’s helped me!

1 Like

Awesome.

Hmm. If you are on a paid plan you can look at using a database trigger (i.e. “when the M1L1 variable changes, change the M1 value”). Tutorial here. Other than that, as the data is currently structured, I’m out of ideas. As I hinted earlier you could create a field on the User thing called “completed modules” (make it a list) then when user completes a module use a workflow to add the module to that list. Then in your progress bar just change the value to “Current Users’ Completed Modules: count”.

Just FYI I don’t know your goals or the context too much here but IMO there are better ways to go about structuring this site. E.g. you should not need a separate page for each module - generally anytime you find yourself repeating layouts / actions something has gone wrong… Anyway, just a note - might not matter for your purposes!

Rob.

Hi. Maybe another approach. Datatype: module with fields; module name (text), total lessons(number), current progress(number),completed (yes/no), For User(user).

Set current progress value to 0(zero) by default, use a trigger when lesson one is completed to set current progress to 1, lesson 2 set current progress 2 and so on. You can then track how many lesson left. When current progress value = total lessons. Change completed to =yes.

Hope it could work.

1 Like