# View: revenue_pie_chart

**View Name:** revenue_pie_chart
**Table Source:** `Derived from: Art_Tracks, Dbt_Prod.Youtube_Ad_Supported_Mrr_Update, Dbt_Prod.Youtube_Subscription_Mrr_Update, Intelligence.Dbt_Prod, Latest_Month`
**File Path:** `views/yt_performance_report/revenue_pie_chart.view.lkml`

## Overview

- **File Size:** 3668 bytes
- **Lines of Code:** 114
- **Dimensions:** 1
- **Measures:** 1
- **Dimension Groups:** 0
- **Filters:** 0

## Dimensions

| Name | Type |
|------|------|
| `content_Type` | string |

## Measures

| Name | Type |
|------|------|
| `total_revenue` | sum |

## Derived Table

```sql
sql:
   WITH latest_month AS (
    SELECT MAX(download_date) AS max_download_date
    FROM INTELLIGENCE.DBT_PROD.YOUTUBE_AD_SUPPORTED_MRR_UPDATE
),

ugc AS (
    SELECT
        ad.download_date,
        ad.partner_revenue + sub.partner_revenue AS total_revenue,
        'UGC' AS content_type
    FROM (
        SELECT ad_supported.download_date     AS download_date,
               SUM(ad_supported.partner_revenue) AS partner_revenue
        FROM INTELLIGENCE.DBT_PROD.YOUTUBE_AD_SUPPORTED_MRR_UPDATE ad_supported
        JOIN latest_month lm
          ON ad_supported.download_date = lm.max_download_date
        WHERE ad_supported.content_type = 'UGC'
        GROUP BY 1
    ) AS ad
    INNER JOIN (
        SELECT sub.download_date,
               SUM(sub.partner_revenue) AS partner_revenue
        FROM INTELLIGENCE.DBT_PROD.YOUTUBE_SUBSCRIPTION_MRR_UPDATE sub
        JOIN latest_month lm
          ON sub.download_date = lm.max_download_date
        WHERE sub.content_type = 'UGC'
        GROUP BY 1
    ) AS sub
      ON ad.download_date = sub.download_date
),

premium AS (
    SELECT
        ad.download_date,
        ad.partner_revenue + sub.partner_revenue AS total_revenue,
        'Premium' AS content_type
    FROM (
        SELECT ad_supported.download_date AS download_date,
               SUM(ad_supported.partner_revenue) AS partner_revenue
        FROM INTELLIGENCE.DBT_PROD.YOUTUBE_AD_SUPPORTED_MRR_UPDATE ad_supported
        JOIN latest_month lm
          ON ad_supported.download_date = lm.max_download_date
        WHERE ad_supported.content_type IN ('Partner-provided', 'Premium UGC')
          AND ad_supported.custom_id NOT LIKE 'ArtTrack%'
        GROUP BY 1
    ) AS ad
    INNER JOIN (
        SELECT sub.download_date,
               SUM(sub.partner_revenue) AS partner_revenue
        FROM INTELLIGENCE.DBT_PROD.YOUTUBE_SUBSCRIPTION_MRR_UPDATE sub
        JOIN latest_month lm
          ON sub.download_date = lm.max_download_date
        WHERE sub.content_type IN ('Partner-provided', 'Premium UGC')
          AND sub.custom_id NOT LIKE 'ArtTrack%'
        GROUP BY 1
    ) AS sub
      ON ad.download_date = sub.download_date
),

art_tracks AS (
    SELECT
        ad.download_date,
        ad.partner_revenue + sub.partner_revenue AS total_revenue,
        'Art Track' AS content_type
    FROM (
        SELECT ad_supported.download_date AS download_date,
               SUM(ad_supported.partner_revenue) AS partner_revenue
        FROM INTELLIGENCE.DBT_PROD.YOUTUBE_AD_SUPPORTED_MRR_UPDATE ad_supported
        JOIN latest_month lm
          ON ad_supported.download_date = lm.max_download_date
        WHERE ad_supported.content_type = 'Partner-provided'
          AND ad_supported.custom_id LIKE 'ArtTrack%'
        GROUP BY 1
    ) AS ad
    INNER JOIN (
        SELECT sub.download_date,
               SUM(sub.partner_revenue) AS partner_revenue
        FROM INTELLIGENCE.DBT_PROD.YOUTUBE_SUBSCRIPTION_MRR_UPDATE sub
        JOIN latest_month lm
          ON sub.download_date = lm.max_download_date
        WHERE sub.content_type = 'Partner-provided'
          AND sub.custom_id LIKE 'ArtTrack%'
        GROUP BY 1
    ) AS sub
      ON ad.download_date = sub.download_date
)

SELECT content_type, total_revenue
FROM ugc
UNION ALL
SELECT content_type, total_revenue FROM premium
UNION ALL
SELECT content_type, total_revenue FROM art_tracks

    ;;
```

