You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -138,7 +138,7 @@ You may want to materialize the results as a fixed table for querying. This is n
138
138
When [dbt server](https://blog.getdbt.com/licensing-dbt/) is released in late 2022, you will be able to access these macros interactively, without needing to build each variant as a single dbt model. For more information, check out the [keynote presentation from Coalesce 2021](https://www.getdbt.com/coalesce-2021/keynote-the-metrics-system/).
139
139
140
140
# Secondary calculations
141
-
Secondary calculations are window functions which act on the primary metric. You can use them to compare a metric's value to an earlier period and calculate year-to-date sums or rolling averages.
141
+
Secondary calculations are window functions which act on the primary metric or metrics. You can use them to compare values to an earlier period and calculate year-to-date sums or rolling averages.
142
142
143
143
Create secondary calculations using the convenience [constructor](https://en.wikipedia.org/wiki/Constructor_(object-oriented_programming)) macros. Alternatively, you can manually create a list of dictionary entries (not recommended).
144
144
@@ -157,29 +157,40 @@ Create secondary calculations using the convenience [constructor](https://en.wik
157
157
Column aliases are [automatically generated](#secondary-calculation-column-aliases), but you can override them by setting `alias`.
158
158
159
159
## Period over Period ([source](/macros/secondary_calculations/secondary_calculation_period_over_period.sql))
160
+
The period over period secondary calculation performs a calculation against the metric(s) in question by either determining the difference or the ratio between two points of time. This other point in time is determined by the input variable which looks at the grain selected in the macro.
|`comparison_strategy`|`ratio` or `difference`| How to calculate the delta between the two periods | Yes |
167
+
|`interval`| 1 | Integer - the number of time grains to look back | Yes |
168
+
|`alias`| 'week_over_week' | The column alias for the resulting calculation | No |
169
+
|`metric_list`| 'base_sum_metric' | List of metrics that the secondary calculation should be applied to. Default is all metrics selected | No |
166
170
167
171
## Period to Date ([source](/macros/secondary_calculations/secondary_calculation_period_to_date.sql))
172
+
The period to date secondary calculation performs an aggregation on a defined **period** of time that is equal to or coarser (higher, more aggregated) than the grain selected. Great example of this is when you want to display a month_to_date value alongside your weekly grained metric.
168
173
169
-
Constructor: `metrics.period_to_date(aggregate, period [, alias])`
174
+
Constructor: `metrics.period_to_date(aggregate, period [, alias, metric_list])`
170
175
171
-
-`aggregate`: The aggregation to use in the window function. Options vary based on the primary aggregation and are enforced in [validate_aggregate_coherence()](/macros/secondary_calculations/validate_aggregate_coherence.sql). Required
172
-
-`period`: The time grain to aggregate to. One of [`"day"`, `"week"`, `"month"`, `"quarter"`, `"year"`]. Must be at equal or lesser granularity than the metric's grain (see [Time Grains](#time-grains) below). Required
173
-
-`alias`: The column alias for the resulting calculation. Optional
|`aggregate`|`max`, `average`| The aggregation to use in the window function. Options vary based on the primary aggregation and are enforced in [validate_aggregate_coherence()](/macros/secondary_calculations/validate_aggregate_coherence.sql). | Yes |
179
+
|`period`|`"day"`, `"week"`| The time grain to aggregate to. One of [`"day"`, `"week"`, `"month"`, `"quarter"`, `"year"`]. Must be at equal or coarser (higher, more aggregated) granularity than the metric's grain (see [Time Grains](#time-grains) below). In example grain of `month`, the acceptable periods would be `month`, `quarter`, or `year`. | Yes |
180
+
|`alias`| 'month_to_date' | The column alias for the resulting calculation | No |
181
+
|`metric_list`| 'base_sum_metric' | List of metrics that the secondary calculation should be applied to. Default is all metrics selected | No |
174
182
175
183
## Rolling ([source](/macros/secondary_calculations/secondary_calculation_rolling.sql))
184
+
The rolling secondary calculation performs an aggregation on a defined number of rows in metric dataset. For example, if the user selects the `week` grain and sets a rolling secondary calculation to `4` then the value returned will be a rolling 4 week calculation of whatever aggregation type was selected.
-`aggregate`: The aggregation to use in the window function. Options vary based on the primary aggregation and are enforced in [validate_aggregate_coherence()](/macros/secondary_calculations/validate_aggregate_coherence.sql). Required
180
-
-`interval`: The number of periods to look back. Required
181
-
-`alias`: The column alias for the resulting calculation. Optional
|`aggregate`|`max`, `average`| The aggregation to use in the window function. Options vary based on the primary aggregation and are enforced in [validate_aggregate_coherence()](/macros/secondary_calculations/validate_aggregate_coherence.sql). | Yes |
191
+
|`interval`| 1 | Integer - the number of time grains to look back | Yes |
192
+
|`alias`| 'month_to_date' | The column alias for the resulting calculation | No |
193
+
|`metric_list`| 'base_sum_metric' | List of metrics that the secondary calculation should be applied to. Default is all metrics selected | No |
183
194
184
195
# Customisation
185
196
Most behaviour in the package can be overridden or customised.
0 commit comments