# View: cm_spotify_change

**View Name:** cm_spotify_change
**Table Source:** `INTELLIGENCE.DBT_PROD.CM_SPOTIFY_CHANGE`
**File Path:** `cm_spotify_change.view.lkml`

## Overview

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

## Comments & Notes

- derived_table: {
- sql: with spotify_change as (
- #with spotify_artists as (

## Dimensions

| Name | Type |
|------|------|
| `name` | string |

## Measures

| Name | Type |
|------|------|
| `monthly_listeners_current` | max |
| `monthly_listeners_change` | max |

## Derived Table

```sql
#    sql: with spotify_change as (
#
#with spotify_artists as (
#Select *
#from (Select cm_artist as cma, name as name, max(followers_latest) as max_followers
#      from chartmetric.raw_data.spotify_artist sa
#      left join chartmetric.raw_data.cm_artist a on sa.cm_artist = a.id
#      group by 1,2) as dta
#inner join chartmetric.raw_data.spotify_artist sa on dta.cma = sa.cm_artist
#             and dta.max_followers = sa.followers_latest)
#
#select
#        sa.cm_artist as cm_artist,
#        sa.name as name,
#        to_date(s.timestp) as date,
#        s.monthly_listeners,
#        s.followers,
#        s.popularity
#from CHARTMETRIC.RAW_DATA.SPOTIFY_ARTIST_STAT s
#left join spotify_artists sa on s.spotify_artist = sa.id),
#
#current_spotify as (
#
#select cm_artist, name, max(monthly_listeners) as monthly_listeners_current,
#max(followers) as followers_current, max(popularity) as popularity_current
#from spotify_change
#where date >= (current_date - 4)
#group by 1,2),
#
#past_spotify as (
#select cm_artist as cm_artist2, name as name2, max(monthly_listeners) as monthly_listeners_past,
#max(followers) as followers_past, max(popularity) as popularity_past
#from spotify_change
#where date <= (current_date - 8) and date >= (current_date - 12)
#group by 1,2)
#
#select cm_artist, name, monthly_listeners_current,
#((monthly_listeners_current - monthly_listeners_past)/nullifzero(monthly_listeners_past)) as monthly_listeners_change,
#followers_current,
#((followers_current - followers_past)/nullifzero(followers_past)) as followewrs_change,
#popularity_current,
#((popularity_current - popularity_past)/nullifzero(popularity_past)) as popularity_change
#from current_spotify cs
#left join past_spotify ps on cs.cm_artist = ps.cm_artist2
#group by 1,2,3,4,5,6,7,8 ;;
#
```

