# View: dt_proper_internal_release_schedule

**View Name:** dt_proper_internal_release_schedule
**Table Source:** `Derived from: Art_Relations_Prod_Art_Relations.Customer_Master_Master, Art_Relations_Prod_Art_Relations.Product_Physical, Art_Relations_Prod_Art_Relations.Product_Physical_Change_History, Art_Relations_Prod_Art_Relations.Releases, Change_History + 2 more`
**File Path:** `dt_proper_internal_release_schedule.view.lkml`

## Overview

- **File Size:** 1964 bytes
- **Lines of Code:** 55
- **Dimensions:** 2
- **Measures:** 0
- **Dimension Groups:** 1
- **Filters:** 1

## Dimensions

| Name | Type |
|------|------|
| `product_id` | number |
| `change_history` | string |

## Dimension Groups

| Name | Type |
|------|------|
| `last_updated` | time |

## Filters

- `date_changed`

## Derived Table

```sql
sql:
 WITH change_history AS (
    SELECT DISTINCT
        ppch.product_id,
        CASE
            WHEN ppch.store_id IS NULL THEN INITCAP(REGEXP_REPLACE(ppch.field_name, '[^a-zA-Z0-9]', ' '))
            ELSE INITCAP(REGEXP_REPLACE(ppch.field_name, '[^a-zA-Z0-9]', ' '))||' - '||cmm.customer_name
            END AS record_type,
        ppch.date_changed
    FROM orchard_app_reporting_v2.art_relations_prod_art_relations.product_physical_change_history ppch
        LEFT JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.customer_master_master cmm ON ppch.store_id = cmm.customer_master_master_id
    WHERE ( store_id IS NULL OR store_id = 696 )
    UNION ALL (
        SELECT pp.release_id, 'New Addition', r.ingestion_completed
        FROM orchard_app_reporting_v2.art_relations_prod_art_relations.product_physical pp
            INNER JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.releases r ON pp.release_id = r.release_id
        WHERE DATEDIFF(hour, r.ingestion_completed, CURRENT_DATE()) <= 168
    )
)
SELECT
    ch.product_id,
    MAX(TO_DATE(ch.date_changed)) AS last_updated,
    LISTAGG(ch.record_type, ', ') WITHIN GROUP (ORDER BY ch.date_changed ASC) AS change_history
FROM change_history ch
    INNER JOIN (
        SELECT product_id, record_type, MAX(date_changed) AS max_date FROM change_history GROUP BY 1,2
    ) md ON ch.product_id = md.product_id AND ch.date_changed = md.max_date
WHERE {% condition date_changed %
```

