Need help with Math Logic

Hey,

I am building a points app. I have students who collect different books.

Once they collect 10 books, they get a title “Reader”.
Once they collect 15 books, they get a title “Treasurer”

I need to send them an email every time they get a title.

Now the logic is:

  • First email sent on 10 Books Collected when they get 1st Readers Title
  • Second email sent on 15 Books Collected when they get 1st Treasurer Title
  • Third email sent on 25 Books Collected when they get 2nd Readers Title
  • Fourth email sent on 30 Books Collected when they get 2nd Treasurer Title
  • Fifth email sent on 40 Books Collected when they get 3rd Readers Title
  • Sixth email sent on 45 Books Collected when they get 3rd Treasurer Title

And so on…

Just can’t figure out the Math Formula for calculating the multiples and implementing the logic.

@glide , can you try answering my question again? I think you are close :grin:

@glide I am building a points app. I have students who collect different books.

Once they collect 10 books, they get a title “Reader”.
Once they collect 15 books, they get a title “Treasurer”

I need to send them an email every time they get a title.

Now the logic is:

  • First email sent on 10 Books Collected when they get 1st Readers Title
  • Second email sent on 15 Books Collected when they get 1st Treasurer Title
  • Third email sent on 25 Books Collected when they get 2nd Readers Title
  • Fourth email sent on 30 Books Collected when they get 2nd Treasurer Title
  • Fifth email sent on 40 Books Collected when they get 3rd Readers Title
  • Sixth email sent on 45 Books Collected when they get 3rd Treasurer Title

How can I implement this logic?

You could use an If then Else column to assign the relevant award to a student based on the number of books in another column. If you bring the list of possible awards into the User table via Single Value you can reference them in the If then Else.

As far as I know, you need to create an action to send the email. Not sure how to auto trigger the email based on a number without an action.

I assume they collect one book at a time, and they collect it by submitting a form. Probably you can use a rollup in the user profiles table to count the number of books they have collected, and an on-submit action on the form to send emails based on the rollup value.

1 Like

Exactly. They collect it by submitting a form. I can do a roll up to count the number of books - that’s an easy part.

This is the logic when the email is supposed to be send. Every time they get a Title, an email has to be sent. I understand that I can do a conditional action on on-submit action of the form but what should be the condition based on the logic stated below:

When they get 10 books, they get 1st “Readers” title. When they get a total of 15 books, they get 1st “Treasurer” Title. Then the logic is repeated. When they get 10 more books, they get 2nd readers title. At this point they have 25 books: (10 + 5 + 10). Then when they get 5 more books, they get 2nd Treasurer Title.

Basically the emails logic is like: 10 + 5 + 10 + 5 + 10 + 5 something like this. Hope I am making sense :frowning:

Since it’s not consistently every 5 books, MOD probably wouldn’t work well. Assuming you already have an IF column to determine the Title, I think what I would do is have a similar IF column that only returns ‘true’ whenever those exact counts are met. That ‘true’ value will be the trigger that tells the custom action that an email needs to be sent.

My only concern would be that when the form is submitted, the counts and IF columns wouldn’t recalculate quickly enough before the email gets sent. Not sure though. If that’s the case, then maybe you need an IF column that shows the NEXT available Title, and set the other IF column to true when the count is 9, 14, 24, etc. That way when the 10th book is submitted, ‘true’ will already be set and the next title will already be set, so the custom action will know to send an email and you you will already have the title you want to send in the email.

Hope that makes sense. I kind of do something similar. I have tests. A certain number of tests need to be passed before a student can get a certain classification. So for example, in the image below, this student has completed all individual tests to get their Bronze, Pre-Silver, and Silver classification. Each classification has multiple tests. Now they are working on their Pre-Gold classification, so they have to complete all tests needed to get that Pre-Gold classification. Once the final test for that classification is completed, then I have an action that will add a new Pre-Gold row, and based on counts, all individual tests will be hidden. I’m pretty sure I have it set up so I already know beforehand, that when the final test is completed, that action will trigger the extra Add Row. My setup is a bit more complicated, but seems very similar to what you want.

I had that in my mind. The thing is, this will limit me to a certain number of books. Let’s say if my user reaches 1000th book, how can I make that work? It would take me forever to set up a IF-ELSE column like that.

OK, so is the 10 + 5 + 10 + 5 pattern consistent then? There’s probably a way to do something mathematically. I’ll see if I can come up with something.

1 Like

Yes 10+5+10+5+10 pattern is consistent yes. Thanks a lot for your time.

Here’s a math formula that should work. Basically any time the result of the math is zero, that means that the number fits your pattern. The if-FitsPattern column is just checking for zero in the mth-Pattern column and returns true if it’s zero.

mod(X,15)*(10-mod(X,15))

1 Like

Not sure if this helps, but I recently needed to do something similar, and the way I approached it was to lay everything out in a table and then dynamically calculate the signed in users level.

My table looked like this:

The logic for determining a users level is very simple and is contained within the currentUserLevel column:

  • If userPoints is less than Lower Limit, then null
  • If userPoints is greater than Upper Limit, then null
  • Else Level

In the example shown in my table, the signed in user has 6 “points”, so their level is Parrot.

To access the signed in users level from other areas of the App, I use a joined list column that targets the currentUserLevel in the above table.

I don’t do any notifications when users switch levels, however I do sometimes need to determine a users “next” level. The way I do this is:

  • Use their current level to form a single relation back to the above table
  • Select the associated Index value via a Lookup
  • Fetch the next level name by using the index value in a single value column (the index numbering deliberately starts at 1 so that this will work).

Not sure if any of this help your use case, but might give you something to think about.

2 Likes

Thank you for the help you guys! I will try out the logics and will update here which works the best :smiley:

1 Like