Merged PR 2124: Denormalized Bank Transactions Mart

A very denormalized table that brings Bank Transactions Line Items, Bank Transactions and Contacts into a single table.

Building this because we need to show some data in a PBI report that needs data from all three tables and can't be joined in PBI.

Related work items: #17551
This commit is contained in:
Pablo Martín 2024-06-26 14:47:18 +00:00
commit 5cc248de9c
2 changed files with 109 additions and 0 deletions

View file

@ -1087,3 +1087,22 @@ models:
The transaction currency is defined at the Bank Transaction level, and
the values you see in this field should always be the same as the
currency of the Bank Transaction this line item belongs to.
- name: xero__bank_transaction_denom_mart.sql
description: |
This model is a denormalized mart, which only exists for presentation
purposes in a PBI report.
The data is the same that lives in `xero__bank_transaction_line_items`,
`xero__bank_transactions` and `xero__contacts`.
The granularity is at line item level, so be careful when doing
aggregations. Most aggregations on data on the transaction or contact
level will be wrong due to duplicates.
columns:
- name: id_line_item
data_type: text
description: Xero's unique identifier for the line item.
tests:
- not_null
- unique

View file

@ -0,0 +1,90 @@
with
xero__bank_transaction_line_items as (
select * from {{ ref("xero__bank_transaction_line_items") }}
),
xero__bank_transactions as (select * from {{ ref("xero__bank_transactions") }}),
xero__contacts as (select * from {{ ref("xero__contacts") }})
select
btli.id_bank_transaction,
btli.id_line_item,
btli.line_description,
btli.id_account,
btli.account_code,
btli.account_name,
btli.item_code,
btli.quantity,
btli.unit_amount,
btli.line_amount_local_curr,
btli.line_amount_in_gbp,
btli.line_amount_wo_taxes_local_curr,
btli.line_amount_wo_taxes_in_gbp,
btli.tax_amount_local_curr,
btli.tax_amount_in_gbp,
btli.tax_type,
btli.transaction_currency_iso_4217,
bt.id_prepayment,
bt.id_overpayment,
bt.id_contact,
bt.id_bank_account,
bt.reference,
bt.transaction_type,
bt.transaction_status,
bt.transaction_at_utc,
bt.transaction_date_utc,
bt.date_string,
bt.total_amount_local_curr,
bt.total_amount_in_gbp,
bt.total_amount_wo_tax_local_curr,
bt.total_amount_wo_tax_in_gbp,
bt.total_tax_local_curr,
bt.total_tax_in_gbp,
bt.exchange_rate_to_gbp,
bt.line_amount_tax_inclusiveness,
bt.is_reconciled,
bt.has_attachments,
bt.url,
bt.external_link_provider_name,
c.account_number,
c.id_deal,
c.contact_name,
c.is_customer,
c.is_supplier,
c.tax_number,
c.contact_first_name,
c.contact_last_name,
c.phones,
c.website,
c.balances,
c.discount,
c.addresses,
c.attachments,
c.email_addresses,
c.payment_terms,
c.batch_payments,
c.branding_theme,
c.contact_groups,
c.contact_number,
c.contact_status,
c.skyper_user_name,
c.contact_persons,
c.xero_network_key,
c.default_currency_iso_4217,
c.validation_errors,
c.bank_account_details,
c.has_validation_errors,
c.tracking_category_name,
c.account_payable_tax_type,
c.tracking_category_option,
c.sales_default_account_code,
c.sales_tracking_categories,
c.account_receivable_tax_type,
c.purchases_default_account_code,
c.purchases_tracking_categories
from xero__bank_transaction_line_items btli
left join
xero__bank_transactions bt on bt.id_bank_transaction = btli.id_bank_transaction
left join xero__contacts c on c.id_contact = bt.id_contact