# View: New_Income_Performers_Blanka

**View Name:** New_Income_Performers_Blanka
**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/New_Income_Performers_Blanka.view.lkml`

## Overview

- **File Size:** 8357 bytes
- **Lines of Code:** 284
- **Dimensions:** 24
- **Measures:** 10
- **Dimension Groups:** 2
- **Filters:** 0

## Dimensions

| Name | Type |
|------|------|
| `Accounting_Run_ID` | string |
| `Accounting_Run_Name` | string |
| `Account_ID` | string |
| `Account_Name` | string |
| `Contract_ID` | string |
| `Contract_Name` | string |
| `Statement_Period` | string |
| `Contributor_Name` | string |
| `Contributor_ID` | string |
| `Contribution_ID` | string |
| `ISRC` | string |
| `Recording_Title` | string |
| `Recording_Version` | string |
| `Recording_Artist` | string |
| `Recording_ID` | string |
| `Society_ID` | string |
| `Source_CMO` | string |
| `Territory` | string |
| `Transaction_Type` | string |
| `Activity_Rate` | number |
| `Royalty_Rate` | number |
| `Payee_Currency` | string |
| `Gross_Acct_Contract` | string |
| `Sale_Currency` | string |

## Measures

| Name | Type |
|------|------|
| `Total_USD` | sum |
| `Withholding_Tax_USD` | sum |
| `Gross_Revenue_Payee_Currency` | sum |
| `Withholding_Tax_Payee_Currency` | sum |
| `Gross_Revenue_After_Withholding_Tax_Payee_Currency` | sum |
| `Net_Share_Payee_Currency` | sum |
| `Gross_Revenue_Sales_Currency` | sum |
| `Withholding_Tax_Sale_Currency` | sum |
| `Gross_Revenue_After_Withholding_Tax_Sale_Currency` | sum |
| `Net_Share_Sale_Currency` | sum |

## Dimension Groups

| Name | Type |
|------|------|
| `Usage_Start_Date` | time |
| `Usage_End_Date` | time |

## SQL Comments

- txn.contributor_name as slaughterhouse_name,
- txn.contributor_only,
- txn.country_id,
- txn.transaction_type as txn_type_abbrev,
- slaughterhouse

## Derived Table

```sql
sql:
     SELECT
    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,
    sp.statement_period_name Statement_Period,
    nc.name Contributor_Name,
    txn.contributor_id Contributor_ID,
    --txn.contributor_name as slaughterhouse_name,
    --txn.contributor_only,
    txn.contribution_id Contribution_ID,
    txn.isrc ISRC,
    cn.name Country,
    --txn.country_id,
    txn.sound_recording_id Recording_ID,
    sr.recording_title Recording_Title,
    sr.version Recording_Version,
    sr.main_artist Recording_Artist,
    txn.store_id Society_ID,
    cmm.customer_name Source_CMO,
    t.transactiontypedesc as Transaction_Type,
    --txn.transaction_type as txn_type_abbrev,
    DATE(txn.start_date, "DD/MM/YYYY") Usage_Start_Date,
    DATE(txn.end_date, "DD/MM/YYYY") Usage_End_Date,
    --slaughterhouse
    --arr.txn_id,
    --txn.quantity,
    --txn.UNIT_PRICE_USD,
    txn.TOTAL_USD Total_USD,
    txn.WITHHOLDING_TAX_USD Withholding_Tax_USD,
    txn.activity_rate Activity_Rate,
    arr.royalty_rate Royalty_Rate,
    --sale currency
    txn.sale_currency_code as Sale_Currency,
    --arr.UNIT_PRICE_SALE_CURRENCY,
    arr.GROSS_REVENUE_SALE_CURRENCY Gross_Revenue_Sales_Currency,
    arr.WITHHOLDING_TAX_SALE_CURRENCY Withholding_Tax_Sale_Currency,
    arr.GROSS_REVENUE_AFTER_WITHHOLDING_TAX_SALE_CURRENCY  Gross_Revenue_After_Withholding_Tax_Sale_Currency,
    arr.NET_SHARE_SALE_CURRENCY Net_Share_Sale_Currency,
    --payee currency
    apt.currency_code as Payee_Currency,
    --arr.unit_price_payee_currency,
    arr.GROSS_REVENUE_PAYEE_CURRENCY Gross_Revenue_Payee_Currency,
    arr.withholding_tax_payee_currency Withholding_Tax_Payee_Currency,
    arr.gross_revenue_after_withholding_tax_payee_currency Gross_Revenue_After_Withholding_Tax_Payee_Currency,
    arr.NET_SHARE_PAYEE_CURRENCY Net_Share_Payee_Currency,
    sum(arr.gross_revenue_after_withholding_tax_payee_currency) over (
        partition by cts.account_id,cts.contract_id order by abs(arr.gross_revenue_payee_currency ) desc rows between unbounded preceding and current row
    ) gross_acct_contract

      -- 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
      -- contrbiutor
      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"."STATEMENT_PERIOD" sp on txn.batch_id=to_char(sp.statement_period_id)
      -- predicates
      where true
      --and arr.accounting_run_id=$accounting_run_id
      --and arr.accounting_run_id=14
      --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 ('66976')
      order by account_id,contract_id;;
```

