Calculate Percentage Change in Bubble

In my Bubble app, I have various newsletter emails stored for different dates.

In the UI, we have a start date picker and an end date picker.

Based on the date selected on the date picker, we are showing the number of email counts between that date range (performing a search for emails with dates >= the start date picker’s value and dates<= the end date picker’s value).

Now, we want to show users the percentage change in email count between the current date range and the same number of days prior.

To do this, we thought of using a simple mathematical expression like:

Email count in the current date range - email count in the previous date range / email count in the previous range's value, formatted as a percentage.

(New number - old number) / old number * 100

However, I am stuck at figuring out the email count of the previous date range.

I have set the end date as the “start date picker’s value”

But for the start date, I am not able to go back to the starting date based on the number of days available in my start and end date picker.

I’ve tried using an expression, but it gives me a positive number of days, so it ends up adding days to the start date instead of subtracting them.

Sorry if I’ve made this explanation more complicated than it needs to be.

If you have any ideas on how to tackle this problem, I’d greatly appreciate your help.

Try this after +days: Start date picker's value - End date picker's value:formatted as days. This should give you a negative day count.

1 Like

Thanks, buddy. I feel a bit silly for not thinking of it that way myself.

1 Like