# What is the best way to calculate variations in percentage?

I have developed a SaaS for hotels to calculate their environmental impact. In the dashboard I need to show a percentage of annual variation. That is, I need to be able to see how much the consumption of water, electricity, gas, waste, etc… has changed.

How should I do the calculation? What is the most efficient way to do it so that it does not consume too much WU?

I am scared that doing the do a search for 7 times (1 per KPIs) would insanely increase my WU consumption

Thank you!

How is the annual usage stored in the DB? Tell us about your data structure.

1st may be try to make your calculation then think about optimisation

I have 1 data type per KPI (electricity, gaz ,water, waste, laundry, CO2)

The data is divided by month in the database.

I already day the following calculation:

((Do a search for electricity 2023 each item item electricity:sum - Do a search for electricity 2024 each item item electricity:sum) / Do a search for electricity 2023 each item item electricity:sum) *100

It does the calculation but now keep in mind that I have to do the same calculation 7 times in the dashboard…

Did it really consume so many WU ?

Are you sure that’s the right approach, versus one data type for the value/date etc with an option set for the resource (gas/electric/CO2)?

Your expression seems fine, the alternative would be storing a calculated number in a different Thing that gets updated with a DB trigger whenever any relevant values change. May work out more efficient depending on the read/write ratio.

I’m not sure I follow you… What do you mean by option set in that case? How would that be done?

Thanks!

Presumably all of your KPI data types are very similar… they all include a value, a year, the User etc

The KPI is the measurement (the Thing). The difference is what you’re measuring (i.e, a property of the Thing = a field, in this case defined by an option set).

This depends on how you’re actually using these KPIs and what you’re storing on them but you get the idea.