Skip to main content

Referencing Measures

Within a metrics view, it is possible for a measure to reference another by using the requires array parameter. By doing this, you could easily aggregate the already existing measures to simplify the expressions. IE: get a percentage of two already summed values.


Please review the reference documentation, here.

Examples

Simple Aggregation

In the following example, percentage_reactive_to_active_measure uses the already defined measures total_global_active_power_measure and total_global_reactive_power_measure to calculate the percentage without having to recalculate the sum of the respective columns.


  - name: percentage_reactive_to_active_measure
display_name: Percent Reactive to Active Power
requires: [total_global_active_power_measure, total_global_reactive_power_measure]
expression: total_global_reactive_power_measure / total_global_active_power_measure
format_preset: percentage

Window Function

If using a window function, you'll need to define the measure that you are building the window for. In this example, we are getting the rolling sum of average voltage measurements for all time, that's a lot of volts! You can modify the frame to include less rows based on the order column.


  - name: rolling_sum_avg_voltage_all_time
display_name: Rolling Sum Windowed Voltage Average
expression: SUM(average_voltage_measure)
requires: [average_voltage_measure]
window:
order: Date
frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
treat_nulls_as: -1

Demo

See this project live in our demo!