HomeGuidesAPI ReferenceChangelog
Log In
Guides

Group & Sort Aggregated Meter Usage Data by Site ID & Unit of Measure

General Explanation

What is this recipe?

This recipe shows how to aggregate monthly, quarterly, or annual meter usage data by site ID and unit of measure (UOM). This recipe is different from Group & Sort Aggregated Meter Usage Data by Site ID & Service Type in that it includes aggregates usages that could not be standardized:

  • horsepower
  • residential cooling
  • hecta liters
  • nm3/h
  • sm3
  • m3/h
  • kgh
  • kg
  • unit
  • undefined
  • gallons (for propane service type)

Use case

What is this recipe for?

This recipe is for users that want to see all aggregated usage values for all meters for a given site and UOM, whether or not the units could be standardized. This can be useful for analyzing usages at different facilities when the meter-level view is too granular.

Snowflake SQL

What’s the snowflake SQL for this recipe?
What does the SQL for this recipe mean?

  1. This first query shows how to aggregate the monthly usage values by site_id, unit_of_measure, and calendarized_month. This sums the monthly meter usage values so that you can see the total usage by site and UOM. It unions the standardized with the non-standardized usages to include the usages that could not be standardized.

    Note that this query also selects the service_type. This is because some UOM and service_type pairs cannot be standardized because they are either not supported or are invalid (like gallons of propane).

with standardized as (
    select site_id
        , calendarized_month
        , round(sum(standardized_monthly_measured_usage), 2) as monthly_measured_usage
        , standardized_monthly_measured_usage_unit_of_measure as unit_of_measure
        , any_value(service_type) as service_type
    from <YOUR_SNOWFLAKE_SHARE>.shares.monthly_usages
    where 
        standardized_monthly_measured_usage is not null
        and site_id is not null
    group by site_id, calendarized_month, unit_of_measure
)

, non_standardized as (
    select site_id
        , calendarized_month
        , round(sum(original_monthly_measured_usage), 2) as monthly_measured_usage
        , original_monthly_measured_usage_unit_of_measure as unit_of_measure
        , any_value(service_type) as service_type
    from <YOUR_SNOWFLAKE_SHARE>.shares.monthly_usages
    where 
        standardized_monthly_measured_usage is null
        and original_monthly_measured_usage is not null
        and site_id is not null
    group by site_id, calendarized_month, unit_of_measure
)

select * from standardized
union all
select * from non_standardized
order by site_id, calendarized_month, unit_of_measure;

This query orders by site, month, and UOM. The order by is applied to the result of the union all so that both standardized and non-standardized usages are sorted together.

You can change the order by statement to surface other types of information:

  • To sort by the highest usage by site by UOM regardless of month:
order by site_id, unit_of_measure, monthly_measured_usage desc
  • To sort by just the highest usage by UOM:
order by unit_of_measure, monthly_measured_usage desc
  1. The next query shows how to aggregate quarterly usages.
with standardized as (
    select site_id
        , calendarized_quarter
        , round(sum(standardized_quarterly_measured_usage), 2) as quarterly_measured_usage
        , standardized_quarterly_measured_usage_unit_of_measure as unit_of_measure
        , any_value(service_type) as service_type
    from <YOUR_SNOWFLAKE_SHARE>.shares.quarterly_usages
    where 
        standardized_quarterly_measured_usage is not null
        and site_id is not null
    group by site_id, calendarized_quarter, unit_of_measure
)

, non_standardized as (
    select site_id
        , calendarized_quarter
        , round(sum(original_quarterly_measured_usage), 2) as quarterly_measured_usage
        , original_quarterly_measured_usage_unit_of_measure as unit_of_measure
        , any_value(service_type) as service_type
    from <YOUR_SNOWFLAKE_SHARE>.shares.quarterly_usages
    where 
        standardized_quarterly_measured_usage is null
        and original_quarterly_measured_usage is not null
        and site_id is not null
    group by site_id, calendarized_quarter, unit_of_measure
)

select * from standardized
union all
select * from non_standardized
order by site_id, calendarized_quarter, unit_of_measure;

The additional sort by expressions documented with the first query can also be used here.

  1. This last query shows how to aggregate annual usages.
with standardized as (
    select site_id
        , calendarized_annual
        , round(sum(standardized_annual_measured_usage), 2) as annual_measured_usage
        , standardized_annual_measured_usage_unit_of_measure as unit_of_measure
        , any_value(service_type) as service_type
    from <YOUR_SNOWFLAKE_SHARE>.shares.annual_usages
    where 
        standardized_annual_measured_usage is not null
        and site_id is not null
    group by site_id, calendarized_annual, unit_of_measure
)

, non_standardized as (
    select site_id
        , calendarized_annual
        , round(sum(original_annual_measured_usage), 2) as annual_measured_usage
        , original_annual_measured_usage_unit_of_measure as unit_of_measure
        , any_value(service_type) as service_type
    from <YOUR_SNOWFLAKE_SHARE>.shares.annual_usages
    where 
        standardized_annual_measured_usage is null
        and original_annual_measured_usage is not null
        and site_id is not null
    group by site_id, calendarized_annual, unit_of_measure
)

select * from standardized
union all
select * from non_standardized
order by site_id, calendarized_annual, unit_of_measure;

The additional sort by expressions documented with the first query can also be used here.

Return format

What’s the return format and an explanation of each returned field?

Monthly usage by site and service type

SITE_IDCALENDARIZED_MONTHMONTHLY_MEASURED_USAGEUNIT_OF_MEASURE
sit_1EC…2023-012342.32gallons
sit_38D…2023-012838.00kwh
sit_38D…2023-0176.00unit
sit_38D…2023-01199.02sm3

Quarterly usage by site and service type

SITE_IDCALENDARIZED_QUARTERQUARTERLY_MEASURED_USAGEUNIT_OF_MEASURE
sit_1EC…2023-q13828.00gallons
sit_38D…2023-q15521.10kwh
sit_38D…2023-q1238.93unit
sit_38D…2023-q1430.0sm3

Annual usage by site and service type

SITE_IDCALENDARIZED_ANNUALANNUAL_MEASURED_USAGEUNIT_OF_MEASURE
sit_1EC…2023234283.00gallons
sit_38D…2023283802.23kwh
sit_38D…20231293.38unit
sit_38D…2023801.37sm3