# View: performer_royalties

**View Name:** performer_royalties
**Table Source:** `Derived from: Prod.Accounting_Run_Results_Nr, Prod.Contract_Transaction_Nr_Staging, Prod.Dim_Transactiontype, Prod.Stmt_Db_Sales_Nr, Prod_Royalty_Accounting_Royalty_Accounting.Account + 3 more`
**File Path:** `views/performer_royalties.view.lkml`

## Overview

- **File Size:** 5120 bytes
- **Lines of Code:** 148
- **Dimensions:** 17
- **Measures:** 0
- **Dimension Groups:** 0
- **Filters:** 0

## Dimensions

| Name | Type |
|------|------|
| `Statement_Period_ID` | string |
| `Statement_Period_Name` | string |
| `Accounting_Run_ID` | string |
| `Accounting_Run_Name` | string |
| `Account_ID` | string |
| `Account_Name` | string |
| `Contract_ID` | string |
| `Contract_Name` | string |
| `Store` | string |
| `Country_Name` | string |
| `Royalty_Rate` | string |
| `Payee_Currency` | string |
| `Total_Gross_Payee_Currency` | number |
| `Total_WHT_Payee_Currency` | number |
| `Total_Gross_After_WHT_Payee_Currency` | number |
| `Net_Revenue_Payee_Currency` | number |
| `Total_Distribution_Fee_Payee_Currency` | number |

## SQL Comments

- payee currency
- contract
- filter out any contracts not KNR label
- account
- contract conditions

## Derived Table

```sql
sql:
      select
    asp.statement_period_id Statement_Period_ID,
    asp.statement_period_name Statement_Period_Name,
    arr.accounting_run_id Accounting_Run_ID,
    arr.accounting_run_name Accounting_Run_Name,
    cts.account_id Account_ID,
    a.account_name Account_Name,
    cts.contract_id Contract_ID,
    c.contract_name Contract_Name,
    cmm.customer_name Store,
    cn.iso3166a3 Country_Name,
    arr.royalty_rate Royalty_Rate,
    --payee currency
    apt.currency_code Payee_Currency,
    round(sum(arr.gross_revenue_payee_currency),5) Total_Gross_Payee_Currency,
    round(sum(arr.withholding_tax_payee_currency),5) Total_WHT_Payee_Currency,
    round(sum(arr.gross_revenue_after_withholding_tax_payee_currency),5) Total_Gross_After_WHT_Payee_Currency,
    round(sum(arr.net_share_payee_currency),5) Net_Revenue_Payee_Currency,
round(-(sum(arr.gross_revenue_after_withholding_tax_payee_currency-arr.net_share_payee_currency)),5) Total_Distribution_Fee_Payee_Currency

-- sales
from royalty_accounting.prod.accounting_run_results_nr as arr
join royalty_accounting.prod.stmt_db_sales_nr as txn on arr.txn_id = txn.stmt_db_sales_nr_txn_id
-- contract
join royalty_accounting.prod.contract_transaction_nr_staging as cts on arr.txn_id = cts.txn_id and cts.accounting_run_id=arr.accounting_run_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.contract as c on cts.contract_id = c.contract_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.run_controller_contract rcc
    on rcc.contract_id=c.contract_id
        and rcc.run_controller_id=6 -- filter out any contracts not KNR label
-- account
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.account as a on cts.account_id = a.account_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.account_payment_term as apt on a.account_id = apt.account_id
-- contract conditions
join facts.prod.dim_transactiontype as t on txn.transaction_type = t.transactiontypeabbr
left join orchard_app_reporting_v2.art_relations_prod_art_relations.customer_master_master cmm on cmm.customer_master_master_id=txn.store_id
left join orchard_app_reporting_v2.art_relations_prod_art_relations.country cn on cn.id=txn.country_id
-- contributor
left join facts.prod.performance_nr_contributor nc on nc.id=txn.contributor_id
---- sound recordings
left join facts.prod.performance_nr_sound_recording sr on sr.id=txn.sound_recording_id
--statement period
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.accounting_run as ari on arr.accounting_run_id = ari.accounting_run_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.accounting_period as api on ari.accounting_period_id = api.accounting_period_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.statement_period as asp on api.statement_period_id = asp.statement_period_id
-- predicates
where true
--and arr.accounting_run_id=$accounting_run_id
--and arr.accounting_run_id=168
--and arr.mechanical_fee_sale_currency != 0
--and arr.ringtone_fee_sale_currency != 0
--and txn.transaction_type = 'as'
--and txn.quantity < 0
--and ctry.countryname = 'usa'
--and txn.isrc = 'gbkpl1356311'
--and txn.contributor_id='2078df88-b9ed-416b-93a5-27f2c6caf858'
--and cts.account_id in ('68920')
group by 1,2,3,4,5,6,7,8,9,10,11,12
order by account_id,contract_id;;
```

