data-dwh-dbt-project/models/intermediate/kpis/int_kpis__agg_mtd_invoiced_revenue.sql
Oriol Roqué Paniagua d12a7233c9 Merged PR 4104: Refactor Invoiced Revenue from Account Code + New Revenue Streams
# Description

Changes:
* Major changes on int_kpis__metric_daily_invoiced_revenue. Now data is retrieved from the account codes, following the previous analysis. This actually reads from a work done on Accounting Codes, with the default aggregations set as a seed. I've also included here new revenue streams for new dash, and the split of guesty fees between resolutions and real API fees. However, New Dash services are still not visible as final metrics. I'll do this separately.
* Propagation of changes in intermediate models. This will affect currently displayed metrics, but not show any new metric.

Since this is quite dense, let's discuss.

# Checklist

- [X] The edited models and dependants run properly with production data.
- [X] The edited models are sufficiently documented.
- [X] The edited models contain PK tests, and I've ran and passed them.
- [X] I have checked for DRY opportunities with other models and docs.
- [X] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

Related work items: #26531
2025-01-20 14:18:05 +00:00

55 lines
2.2 KiB
SQL

{% set dimensions = get_kpi_dimensions_per_model("INVOICED_REVENUE") %}
{{
config(
materialized="table", unique_key=["end_date", "dimension", "dimension_value"]
)
}}
{% for dimension in dimensions %}
select
-- Unique Key --
start_date,
end_date,
{{ dimension.dimension }} as dimension,
{{ dimension.dimension_value }} as dimension_value,
-- Metrics --
sum(
xero_basic_protection_net_fees_in_gbp
) as xero_basic_protection_net_fees_in_gbp,
sum(xero_waiver_pro_net_fees_in_gbp) as xero_waiver_pro_net_fees_in_gbp,
sum(
xero_id_verification_net_fees_in_gbp
) as xero_id_verification_net_fees_in_gbp,
sum(
xero_protection_plus_net_fees_in_gbp
) as xero_protection_plus_net_fees_in_gbp,
sum(xero_screening_plus_net_fees_in_gbp) as xero_screening_plus_net_fees_in_gbp,
sum(
xero_sex_offenders_check_net_fees_in_gbp
) as xero_sex_offenders_check_net_fees_in_gbp,
sum(xero_protection_pro_net_fees_in_gbp) as xero_protection_pro_net_fees_in_gbp,
sum(
xero_basic_screening_net_fees_in_gbp
) as xero_basic_screening_net_fees_in_gbp,
sum(xero_booking_net_fees_in_gbp) as xero_booking_net_fees_in_gbp,
sum(xero_listing_net_fees_in_gbp) as xero_listing_net_fees_in_gbp,
sum(xero_verification_net_fees_in_gbp) as xero_verification_net_fees_in_gbp,
sum(xero_operator_net_fees_in_gbp) as xero_operator_net_fees_in_gbp,
sum(
xero_waiver_paid_back_to_host_in_gbp
) as xero_waiver_paid_back_to_host_in_gbp,
sum(xero_e_deposit_net_fees_in_gbp) as xero_e_deposit_net_fees_in_gbp,
sum(xero_athena_net_fees_in_gbp) as xero_athena_net_fees_in_gbp,
sum(xero_guesty_net_fees_in_gbp) as xero_guesty_net_fees_in_gbp,
sum(xero_apis_net_fees_in_gbp) as xero_apis_net_fees_in_gbp,
sum(
xero_guesty_resolutions_net_fees_in_gbp
) as xero_guesty_resolutions_net_fees_in_gbp
from {{ ref("int_kpis__metric_mtd_invoiced_revenue") }}
group by 1, 2, 3, 4
{% if not loop.last %}
union all
{% endif %}
{% endfor %}