TABLE OF CONTENTS
How does the Calculation Measure work?
Calculation allows the creation of calculations on the canvas. The calculation formula is created by using an Excel-like syntax. Different measures are referred to by system name. A calculation can include:
- Numerical values.
- Sum results.
- Results from other calculations.
- Dynamic values based on the Reporters choice in a dropdown.
Example of dynamic values, if a dropdown contains a list of energy mixes each with an emission factor, when the reporter selects from the dropdown, the values of the chosen option will be included in the calculation.
Calculation in the Measure Builder.
When referring to another measure in the calculation formula, the variables are highlighted in light blue. When clicking them, the Canvas will light up the connected measures in yellow.
Variables highlighted when referred to and connected.
To the right of the measure builder, in the settings you can find the following options:
- Name
- Unit - From a list or your custom unit
- Number format - Number or General
- Select number of decimals to show - The number of decimals that will be shown to the reporter
- Use thousand separator - See the example below.
- unticked - The number will be shown as 2000
- ticked - The number will be shown as 2 000 (SWE) or 2,000 (ENG)
- Calculation formula
- Data missing text
- Description
- Show result - Would you like it to be a hidden calculation? In that case, the data will be accessible in Analytics but not shown to the reporter.
Example 1.
In this example, four numbers are part of two calculations (notice how they are combined in the parenthesis). The sum result of the two numbers is then calculated at the top. See the top image for the measure builder and the bottom video for how it looks to the reporter.
Note: calculations will not display any result until all required data has been reported.
Advanced
Data missing text
Until all required numbers in the canvas have been reported, the Calculation measure will show this text. The default text is "-".
Show calculation result
When enabled, the calculation will be shown for the Reporter in the canvas. It is turned on by default.
This can be if intermediate calculations are needed in the canvas and/or data exports but are not to be displayed for the Reporter.
Example 2.
In this example, four numbers are part of two calculations (notice how they are combined in the parenthesis). The sum result of the two calculations is then calculated in the calculation at the top.
Four number inputs, three calculations.
The resulting survey:
Note how the calculations will not display any result until all required data has been reported.
Approved mathematical expressions
Except for the ordinary +/-*
- Expression for exponential equation pow(a, b) - (e.g. pow(3, 2) = 3² = 9) pow(a, b) - (e.g. pow(3, 2) = 3² = 9)
- Expression for square root sqrt(a) - (e.g. sqrt(9) = 3)
- Expression for returning the smallest number min(a, b, ...) of all given numbers - (e.g. min(10, 20, 15) = 10)
- Expression for returning the largest number max(a, b, ...) all given numbers - (e.g. max(10, 20, 15) = 20)
Examples of advanced calculation components
Example 3: Referring to a list item based on a drop-down option in a calculation
If you want to refer to a factor that changes based on the reporter's choice in a dropdown list, the keyword data is used.
See the example below, where the system name of the dropdown measure is EnergyMix and the value of the list item is {"factor_scope_2": 329.19} :
EnergyMix.data.factor_scope_2
Example 4: Referring to a list item in a calculation
It is recommended to store factors that are used in a calculation in a list that can change over time using the valid-from-date. This list should be stored in one place and not duplicated in many calculations over multiple measures. To refer to a list element it is possible to use a special keyword pgLists. Read more about how to manage lists.
See the example below, where the PrettyID of the list is energy_list, the PrettyID of the list item is water_item and the value of the list item is {"factor_scope_1": 23} :
pgLists.energy_list.water_item.factor_scope_1
Example 5: Referring to different list items in a calculation depending on the organizational unit
If you would like to refer to different list items in a calculation depending on the organizational unit you are reporting for, you should use the same Pretty Id to the list items as its matching organizational unit.
If the Pretty Id of the organizational unit is "Stockholm", the Pretty Id of its matching list item should also be "Stockholm". If the Pretty Id of the list is energy_list, and the value of the list item is {"factor_heating_scope_2": 232}, the code in the measure should be:
(listValue("energy_list",orgUnitPrettyId)).factor_heating_scope_2
Example 6: Referencing a number that allows data missing
When referencing a number in a calculation that allows data missing you have to make a choice. The calculation will not be able to produce a calculation result if one of the input variables is marked as missing by the reporter. This might be the desired behavior, for example in a calculation that will calculate an average you might not want to include the value if is marked as missing. On the other hand, if the calculation is supposed to do a sum of two numbers then the default value can be 0.
By default, the calculation will not be able to produce a result if the number measure_missing is marked as missing.
measure_missing + 10
To set a default value (0) if the number is marked as missing you can update the expression to use the getValue function and provide a default value. This can be useful if the calculation is based on a conditional measure that might not always have a value. The formula can be used like this:
getValue(measure_missing, 0) + 10
If a measure must be determined, then the hasValue function can be applied. For example, if the number is marked as missing and a control figure can be used the syntax is as follows:
(hasValue(measure_missing) ? measure_missing : other_control) * 100
Expression | Value of number_control | Result |
---|---|---|
number_control + 10 | 5 | 15 |
number_control + 10 | Missing | - |
getValue(number_control, 0) + 10 | 5 | 15 |
getValue(number_control, 0) + 10 | Missing | 10 |
hasValue(number_control) ? number_control : 5 | 100 | 100 |
hasValue(number_control) ? number_control : 5 | Missing | 5 |
Example 7: calculating a value depending on other measures values
If you would like to give a calculation a value depending on the value of other measures, you can use the example below as a template.
measure_1 == 'DBYes' or measure_2 == 'DBNo' ? 1 : 0
Syntax | Meaning |
---|---|
measure_1 | if measure_1 |
== | equals |
'DBYes' | yes |
or | or |
measure_2 | if measure_2 |
== | equals |
'DBNo' | no |
? | then |
1 | paste the value 1 |
: | otherwise |
0 | paste the value 2 |
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article