Repository: TEAMSchools/teamster
Pull request #2635: RTI MTSS roster
Author: login: anthonygwalters
Created: 2025-04-22T17:32:41Z | Merged: 2025-04-22T20:09:08Z

# Pull Request

## Summary & Motivation

[//]: # "When merged, this pull request will..."

## Self-review

**If this is a same-day request, please flag that in our Slack channel!**

- [ ] Update **due date**, **assignee**, and **priority** on our
      [TEAMster Asana Project](https://app.asana.com/0/1205971774138578/1205971926225838)
- [ ] <kbd>Format</kbd> has been run on all modified files

### SQL

- [ ] Ensure you are using the `union_dataset_join_clause()` macro for queries
      that employ any models using these datasets: `deanslist` `edplan` `iready`
      `overgrad` `pearson` `powerschool` `renlearn` `titan`
- [ ] All `distinct` usage must be accompanied by an comment explaining it's
      necessity
- [ ] If you are adding a new external source, run:

      dbt run-operation stage_external_sources --vars
      "ext_full_refresh: true"

## Troubleshooting

- [SqlFluff Rules Reference](https://docs.sqlfluff.com/en/stable/rules.html)
- [Trunk](https://teamschools.github.io/teamster/CONTRIBUTING/#trunk)
- [dbt](https://teamschools.github.io/teamster/CONTRIBUTING/#dbt-cloud_1)


---
- To see the specific tasks where the Asana app for GitHub is being used, see below:
  - https://app.asana.com/0/0/1210049220786671


Diff:
diff --git a/src/dbt/kipptaf/models/deanslist/intermediate/int_deanslist__referral_suspension_rollup.sql b/src/dbt/kipptaf/models/deanslist/intermediate/int_deanslist__referral_suspension_rollup.sql
new file mode 100644
index 0000000000..8a5fc5aaa5
--- /dev/null
+++ b/src/dbt/kipptaf/models/deanslist/intermediate/int_deanslist__referral_suspension_rollup.sql
@@ -0,0 +1,120 @@
+with
+    suspension_type as (
+        select penalty_name, 'ISS' as suspension_type,
+        from
+            unnest(
+                [
+                    'In School Suspension',
+                    'KM: In-School Suspension',
+                    'KNJ: In-School Suspension'
+                ]
+            ) as penalty_name
+
+        union all
+
+        select penalty_name, 'OSS' as suspension_type,
+        from
+            unnest(
+                [
+                    'Out of School Suspension',
+                    'KM: Out-of-School Suspension',
+                    'KNJ: Out-of-School Suspension'
+                ]
+            ) as penalty_name
+    ),
+
+    incidents as (
+        select
+            *,
+            case
+                when regexp_extract(category, r'^(.*?)\s*-\s*') in ('SW', 'SS', 'SSC')
+                then 'Social Work'
+                when
+                    regexp_extract(category, r'^(.*?)\s*-\s*') = 'TX'
+
+                    or category in ('School Clinic', 'Incident Report/Accident Report')
+                then 'Non-Behavioral'
+                when
+                    (
+                        regexp_extract(category, r'^(.*?)\s*-\s*') in ('T1', 'Tier 1')
+                        and regexp_extract(_dbt_source_relation, r'(kipp\w+)_')
+                        != 'kippmiami'
+                    )
+                    or (
+                        regexp_extract(category, r'^(.*?)\s*-\s*') in ('T4', 'T3')
+                        and regexp_extract(_dbt_source_relation, r'(kipp\w+)_')
+                        = 'kippmiami'
+                    )
+                then 'Low'
+                when regexp_extract(category, r'^(.*?)\s*-\s*') in ('T2', 'Tier 2')
+                then 'Middle'
+                when
+                    (
+                        regexp_extract(category, r'^(.*?)\s*-\s*') in ('T3', 'Tier 3')
+                        and regexp_extract(_dbt_source_relation, r'(kipp\w+)_')
+                        != 'kippmiami'
+                    )
+                    or (
+                        regexp_extract(category, r'^(.*?)\s*-\s*') = 'T1'
+                        and regexp_extract(_dbt_source_relation, r'(kipp\w+)_')
+                        = 'kippmiami'
+                    )
+                then 'High'
+                when category is null
+                then null
+                else 'Other'
+            end as referral_tier,
+        from {{ ref("stg_deanslist__incidents") }}
+    )
+
+select
+    dli.student_school_id,
+    dli.create_ts_academic_year,
+
+    count(
+        distinct if(dlp.is_suspension, dlp.incident_penalty_id, null)
+    ) as suspension_count_all,
+    count(
+        distinct if(
+            dlp.is_suspension and st.suspension_type = 'OSS',
+            dlp.incident_penalty_id,
+            null
+        )
+    ) as suspension_count_oss,
+    count(
+        distinct if(
+            dlp.is_suspension and st.suspension_type = 'ISS',
+            dlp.incident_penalty_id,
+            null
+        )
+    ) as suspension_count_iss,
+    sum(if(dlp.is_suspension, dlp.num_days, null)) as days_suspended_all,
+    sum(
+        if(dlp.is_suspension and st.suspension_type = 'OSS', dlp.num_days, null)
+    ) as days_suspended_oss,
+    sum(
+        if(dlp.is_suspension and st.suspension_type = 'ISS', dlp.num_days, null)
+    ) as days_suspended_iss,
+
+    count(distinct dli.incident_id) as referral_count_all,
+    count(
+        distinct if(dli.referral_tier = 'High', dli.incident_id, null)
+    ) as referral_count_high,
+    count(
+        distinct if(dli.referral_tier = 'Middle', dli.incident_id, null)
+    ) as referral_count_middle,
+    count(
+        distinct if(dli.referral_tier = 'low', dli.incident_id, null)
+    ) as referral_count_low,
+from incidents as dli
+left join
+    {{ ref("stg_deanslist__incidents__penalties") }} as dlp
+    on dli.incident_id = dlp.incident_id
+    and {{ union_dataset_join_clause(left_alias="dli", right_alias="dlp") }}
+left join
+    {{ ref("int_deanslist__incidents__custom_fields__pivot") }} as cf
+    on dli.incident_id = cf.incident_id
+    and {{ union_dataset_join_clause(left_alias="dli", right_alias="cf") }}
+left join suspension_type as st on dlp.penalty_name = st.penalty_name
+where dli.referral_tier not in ('Non-Behavioral', 'Social Work')
+group by dli.student_school_id, dli.create_ts_academic_year
diff --git a/src/dbt/kipptaf/models/extracts/google/sheets/rpt_gsheets__mtss_rti.sql b/src/dbt/kipptaf/models/extracts/google/sheets/rpt_gsheets__mtss_rti.sql
new file mode 100644
index 0000000000..3b92450bdd
--- /dev/null
+++ b/src/dbt/kipptaf/models/extracts/google/sheets/rpt_gsheets__mtss_rti.sql
@@ -0,0 +1,135 @@
+with
+    iready_long as (
+        select
+            student_id,
+            academic_year_int,
+
+            lower(subject) as subject,
+            concat(
+                most_recent_overall_relative_placement,
+                ' (',
+                most_recent_completion_date,
+                ')'
+            ) as iready_most_recent,
+        from {{ ref("base_iready__diagnostic_results") }}
+        where rn_subj_year = 1
+    ),
+
+    iready_pivot as (
+        select student_id, academic_year_int, reading, math,
+        from
+            iready_long
+            pivot (max(iready_most_recent) for subject in ('reading', 'math'))
+    ),
+
+    dibels_recent as (
+        select
+            mclass_academic_year,
+            mclass_student_number,
+            mclass_client_date,
+            mclass_measure_standard_level,
+
+            'Reading' as iready_subject,
+
+            row_number() over (
+                partition by mclass_academic_year, mclass_student_number
+                order by mclass_client_date desc
+            ) as rn_benchmark,
+        from {{ ref("int_amplify__all_assessments") }}
+        where mclass_measure_standard = 'Composite'
+    ),
+
+    gpa as (
+        select studentid, _dbt_source_relation, schoolid, yearid, gpa_y1,
+        from {{ ref("int_powerschool__gpa_term") }}
+        where is_current
+    ),
+
+    roster as (
+        select
+            co.academic_year,
+            co.region,
+            co.school,
+            co.student_number,
+            co.student_name,
+            co.grade_level,
+            co.advisory,
+            co.boy_status,
+            co.iep_status,
+            co.lep_status,
+            co.is_504,
+            co.ada,
+
+            g.gpa_y1 as gpa_y1_current,
+
+            case
+                when co.enroll_status = 0
+                then 'Currently Enrolled'
+                when co.enroll_status = 2
+                then 'Transferred Out'
+                when co.enroll_status = 3
+                then 'Graduated'
+                when co.enroll_status = -1
+                then 'Pre-Enrolled'
+            end as enrollment_status,
+            lag(co.ada, 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as ada_prev_year,
+
+            coalesce(ir.reading, 'No Data') as most_recent_iready_reading_current,
+            coalesce(ir.math, 'No Data') as most_recent_iready_math_current,
+            lag(coalesce(ir.reading, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_iready_reading_prev_year,
+            lag(coalesce(ir.math, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_iready_math_prev_year,
+
+            coalesce(
+                dr.mclass_measure_standard_level, 'No Data'
+            ) as most_recent_dibels_composite_current,
+            lag(coalesce(dr.mclass_measure_standard_level, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_dibels_composite_prev_year,
+
+            lag(g.gpa_y1, 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as gpa_y1_prev_year,
+
+            coalesce(sr.days_suspended_oss, 0) as days_suspended_oss_current,
+            coalesce(sr.days_suspended_all, 0) as days_suspended_all_current,
+            lag(coalesce(sr.days_suspended_oss, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as days_suspended_oss_prev_year,
+            lag(coalesce(sr.days_suspended_all, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as days_suspended_all_prev_year,
+            coalesce(sr.referral_count_all, 0) as referral_count_current,
+            lag(coalesce(sr.referral_count_all, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as referral_count_prev_year,
+        from {{ ref("int_extracts__student_enrollments") }} as co
+        left join
+            iready_pivot as ir
+            on co.student_number = ir.student_id
+            and co.academic_year = ir.academic_year_int
+        left join
+            dibels_recent as dr
+            on co.student_number = dr.mclass_student_number
+            and co.academic_year = dr.mclass_academic_year
+            and dr.rn_benchmark = 1
+        left join
+            gpa as g
+            on co.studentid = g.studentid
+            and co.schoolid = g.schoolid
+            and co.yearid = g.yearid
+            and {{ union_dataset_join_clause(left_alias="co", right_alias="g") }}
+        left join
+            {{ ref("int_deanslist__referral_suspension_rollup") }} as sr
+            on co.student_number = sr.student_school_id
+            and co.academic_year = sr.create_ts_academic_year
+    )
+
+select *,
+from roster
+where academic_year = {{ var("current_academic_year") }}
diff --git a/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__okrts_referrals.sql b/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__okrts_referrals.sql
index da616cf2ac..4320825b2e 100644
--- a/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__okrts_referrals.sql
+++ b/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__okrts_referrals.sql
@@ -212,7 +212,7 @@ select
     concat(dli.create_last, ', ', dli.create_first) as entry_staff,
     concat(dli.update_last, ', ', dli.update_first) as last_update_staff,
     case
-        when left(dli.category, 2) in ('SW', 'SS')
+        when left(dli.category, 2) in ('SW', 'SS') or left(dli.category, 3) = 'SSC'
         then 'Social Work'
         when left(dli.category, 2) = 'TX'
         then 'Non-Behavioral'
diff --git a/src/dbt/kipptaf/models/iready/base/base_iready__diagnostic_results.sql b/src/dbt/kipptaf/models/iready/base/base_iready__diagnostic_results.sql
index 38fa7cbc03..35ae155718 100644
--- a/src/dbt/kipptaf/models/iready/base/base_iready__diagnostic_results.sql
+++ b/src/dbt/kipptaf/models/iready/base/base_iready__diagnostic_results.sql
@@ -78,6 +78,10 @@ with
                 partition by _dbt_source_relation, student_id, academic_year, `subject`
             ) as most_recent_rush_flag,
 
+            max(if(most_recent_diagnostic_ytd_y_n = 'Y', completion_date, null)) over (
+                partition by _dbt_source_relation, student_id, academic_year, `subject`
+            ) as most_recent_completion_date,
+
             row_number() over (
                 partition by _dbt_source_relation, student_id, academic_year, `subject`
                 order by completion_date desc
@@ -118,6 +122,7 @@ select
     dr.most_recent_lexile_measure,
     dr.most_recent_lexile_range,
     dr.most_recent_rush_flag,
+    dr.most_recent_completion_date,
     dr.rn_subj_year,
 
     lc.region,


Reviews:
user: login: cbini
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-04-22T19:05:28Z
user: login: anthonygwalters
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-22T19:37:08Z
user: login: anthonygwalters
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-22T19:46:51Z
user: login: cbini
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-04-22T19:57:04Z

Review comments:
path: src/dbt/kipptaf/models/reporting/intermediate/int_reporting__referral_suspension_rollup.sql
user: login: cbini
body: this should go under `deanslist/`
created_at: 2025-04-22T19:03:52Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,136 @@
+with
+    iready_long as (
+        select
+            student_id,
+            academic_year_int,
+
+            lower(subject) as subject,
+            concat(
+                most_recent_overall_relative_placement,
+                ' (',
+                most_recent_completion_date,
+                ')'
+            ) as iready_most_recent,
+        from {{ ref("base_iready__diagnostic_results") }} as ir
+        where ir.rn_subj_year = 1
+    ),
+
+    iready_pivot as (
+        select student_id, academic_year_int, reading, math,
+        from
+            iready_long
+            pivot (max(iready_most_recent) for subject in ('reading', 'math'))
+    ),
+
+    dibels_recent as (
+        select
+            mclass_academic_year,
+            mclass_student_number,
+            mclass_client_date,
+            mclass_measure_standard_level,
+
+            'Reading' as iready_subject,
+
+            row_number() over (
+                partition by mclass_academic_year, mclass_student_number
+                order by mclass_client_date desc
+            ) as rn_benchmark,
+        from {{ ref("int_amplify__all_assessments") }}
+        where mclass_measure_standard = 'Composite'
+    ),
+
+    gpa as (
+        select studentid, _dbt_source_relation, schoolid, yearid, gpa_y1,
+        from {{ ref("int_powerschool__gpa_term") }}
+        where is_current
+    ),
+
+    roster as (
+        select
+            co.academic_year,
+            co.region,
+            co.school,
+            co.student_number,
+            co.student_name,
+            co.grade_level,
+            co.advisory,
+            co.boy_status,
+            co.iep_status,
+            co.lep_status,
+            co.is_504,
+            co.ada,
+
+            g.gpa_y1 as gpa_y1_current,
+
+            case
+                when co.enroll_status = 0
+                then 'Currently Enrolled'
+                when co.enroll_status = 2
+                then 'Transferred Out'
+                when co.enroll_status = 3
+                then 'Graduated'
+                when co.enroll_status = -1
+                then 'Pre-Enrolled'
+            end as enrollment_status,
+            lag(co.ada, 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as ada_prev_year,
+
+            coalesce(ir.reading, 'No Data') as most_recent_iready_reading_current,
+            coalesce(ir.math, 'No Data') as most_recent_iready_math_current,
+            lag(coalesce(ir.reading, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_iready_reading_prev_year,
+            lag(coalesce(ir.math, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_iready_math_prev_year,
+
+            coalesce(
+                dr.mclass_measure_standard_level, 'No Data'
+            ) as most_recent_dibels_composite_current,
+            lag(coalesce(dr.mclass_measure_standard_level, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_dibels_composite_prev_year,
+
+            lag(g.gpa_y1, 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as gpa_y1_prev_year,
+
+            coalesce(sr.days_suspended_oss, 0) as days_suspended_oss_current,
+            coalesce(sr.days_suspended_all, 0) as days_suspended_all_current,
+            lag(coalesce(sr.days_suspended_oss, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as days_suspended_oss_prev_year,
+            lag(coalesce(sr.days_suspended_all, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as days_suspended_all_prev_year,
+            coalesce(sr.referral_count_all, 0) as referral_count_current,
+            lag(coalesce(sr.referral_count_all, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as referral_count_prev_year,
+        from {{ ref("int_extracts__student_enrollments") }} as co
+        left join
+            iready_pivot as ir
+            on co.student_number = ir.student_id
+            and co.academic_year = ir.academic_year_int
+        left join
+            dibels_recent as dr
+            on co.student_number = dr.mclass_student_number
+            and co.academic_year = dr.mclass_academic_year
+            and dr.rn_benchmark = 1
+        left join
+            gpa as g
+            on co.studentid = g.studentid
+            and co.schoolid = g.schoolid
+            and co.yearid = g.yearid
+            and {{ union_dataset_join_clause(left_alias="co", right_alias="g") }}
+        left join
+            {{ ref("int_reporting__referral_suspension_rollup") }} as sr
+            on co.student_number = sr.student_school_id
+            and co.academic_year = sr.create_ts_academic_year
+        where co.academic_year >= {{ var("current_academic_year") - 1 }}
+    )
+
+select *
+from roster
+where academic_year = {{ var("current_academic_year") }}
path: src/dbt/kipptaf/models/extracts/google/sheets/rpt_gsheets__mtss_rti.sql
user: login: cbini
body: this negates the `academic_year` filter inside of `roster`
created_at: 2025-04-22T19:04:42Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,136 @@
+with
+    iready_long as (
+        select
+            student_id,
+            academic_year_int,
+
+            lower(subject) as subject,
+            concat(
+                most_recent_overall_relative_placement,
+                ' (',
+                most_recent_completion_date,
+                ')'
+            ) as iready_most_recent,
+        from {{ ref("base_iready__diagnostic_results") }} as ir
+        where ir.rn_subj_year = 1
+    ),
+
+    iready_pivot as (
+        select student_id, academic_year_int, reading, math,
+        from
+            iready_long
+            pivot (max(iready_most_recent) for subject in ('reading', 'math'))
+    ),
+
+    dibels_recent as (
+        select
+            mclass_academic_year,
+            mclass_student_number,
+            mclass_client_date,
+            mclass_measure_standard_level,
+
+            'Reading' as iready_subject,
+
+            row_number() over (
+                partition by mclass_academic_year, mclass_student_number
+                order by mclass_client_date desc
+            ) as rn_benchmark,
+        from {{ ref("int_amplify__all_assessments") }}
+        where mclass_measure_standard = 'Composite'
+    ),
+
+    gpa as (
+        select studentid, _dbt_source_relation, schoolid, yearid, gpa_y1,
+        from {{ ref("int_powerschool__gpa_term") }}
+        where is_current
+    ),
+
+    roster as (
+        select
+            co.academic_year,
+            co.region,
+            co.school,
+            co.student_number,
+            co.student_name,
+            co.grade_level,
+            co.advisory,
+            co.boy_status,
+            co.iep_status,
+            co.lep_status,
+            co.is_504,
+            co.ada,
+
+            g.gpa_y1 as gpa_y1_current,
+
+            case
+                when co.enroll_status = 0
+                then 'Currently Enrolled'
+                when co.enroll_status = 2
+                then 'Transferred Out'
+                when co.enroll_status = 3
+                then 'Graduated'
+                when co.enroll_status = -1
+                then 'Pre-Enrolled'
+            end as enrollment_status,
+            lag(co.ada, 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as ada_prev_year,
+
+            coalesce(ir.reading, 'No Data') as most_recent_iready_reading_current,
+            coalesce(ir.math, 'No Data') as most_recent_iready_math_current,
+            lag(coalesce(ir.reading, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_iready_reading_prev_year,
+            lag(coalesce(ir.math, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_iready_math_prev_year,
+
+            coalesce(
+                dr.mclass_measure_standard_level, 'No Data'
+            ) as most_recent_dibels_composite_current,
+            lag(coalesce(dr.mclass_measure_standard_level, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_dibels_composite_prev_year,
+
+            lag(g.gpa_y1, 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as gpa_y1_prev_year,
+
+            coalesce(sr.days_suspended_oss, 0) as days_suspended_oss_current,
+            coalesce(sr.days_suspended_all, 0) as days_suspended_all_current,
+            lag(coalesce(sr.days_suspended_oss, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as days_suspended_oss_prev_year,
+            lag(coalesce(sr.days_suspended_all, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as days_suspended_all_prev_year,
+            coalesce(sr.referral_count_all, 0) as referral_count_current,
+            lag(coalesce(sr.referral_count_all, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as referral_count_prev_year,
+        from {{ ref("int_extracts__student_enrollments") }} as co
+        left join
+            iready_pivot as ir
+            on co.student_number = ir.student_id
+            and co.academic_year = ir.academic_year_int
+        left join
+            dibels_recent as dr
+            on co.student_number = dr.mclass_student_number
+            and co.academic_year = dr.mclass_academic_year
+            and dr.rn_benchmark = 1
+        left join
+            gpa as g
+            on co.studentid = g.studentid
+            and co.schoolid = g.schoolid
+            and co.yearid = g.yearid
+            and {{ union_dataset_join_clause(left_alias="co", right_alias="g") }}
+        left join
+            {{ ref("int_reporting__referral_suspension_rollup") }} as sr
+            on co.student_number = sr.student_school_id
+            and co.academic_year = sr.create_ts_academic_year
+        where co.academic_year >= {{ var("current_academic_year") - 1 }}
+    )
+
+select *
+from roster
path: src/dbt/kipptaf/models/extracts/google/sheets/rpt_gsheets__mtss_rti.sql
user: login: cbini
body: you can drop this and make the `roster` CTE the main statement
created_at: 2025-04-22T19:05:15Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,136 @@
+with
+    iready_long as (
+        select
+            student_id,
+            academic_year_int,
+
+            lower(subject) as subject,
+            concat(
+                most_recent_overall_relative_placement,
+                ' (',
+                most_recent_completion_date,
+                ')'
+            ) as iready_most_recent,
+        from {{ ref("base_iready__diagnostic_results") }} as ir
+        where ir.rn_subj_year = 1
+    ),
+
+    iready_pivot as (
+        select student_id, academic_year_int, reading, math,
+        from
+            iready_long
+            pivot (max(iready_most_recent) for subject in ('reading', 'math'))
+    ),
+
+    dibels_recent as (
+        select
+            mclass_academic_year,
+            mclass_student_number,
+            mclass_client_date,
+            mclass_measure_standard_level,
+
+            'Reading' as iready_subject,
+
+            row_number() over (
+                partition by mclass_academic_year, mclass_student_number
+                order by mclass_client_date desc
+            ) as rn_benchmark,
+        from {{ ref("int_amplify__all_assessments") }}
+        where mclass_measure_standard = 'Composite'
+    ),
+
+    gpa as (
+        select studentid, _dbt_source_relation, schoolid, yearid, gpa_y1,
+        from {{ ref("int_powerschool__gpa_term") }}
+        where is_current
+    ),
+
+    roster as (
+        select
+            co.academic_year,
+            co.region,
+            co.school,
+            co.student_number,
+            co.student_name,
+            co.grade_level,
+            co.advisory,
+            co.boy_status,
+            co.iep_status,
+            co.lep_status,
+            co.is_504,
+            co.ada,
+
+            g.gpa_y1 as gpa_y1_current,
+
+            case
+                when co.enroll_status = 0
+                then 'Currently Enrolled'
+                when co.enroll_status = 2
+                then 'Transferred Out'
+                when co.enroll_status = 3
+                then 'Graduated'
+                when co.enroll_status = -1
+                then 'Pre-Enrolled'
+            end as enrollment_status,
+            lag(co.ada, 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as ada_prev_year,
+
+            coalesce(ir.reading, 'No Data') as most_recent_iready_reading_current,
+            coalesce(ir.math, 'No Data') as most_recent_iready_math_current,
+            lag(coalesce(ir.reading, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_iready_reading_prev_year,
+            lag(coalesce(ir.math, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_iready_math_prev_year,
+
+            coalesce(
+                dr.mclass_measure_standard_level, 'No Data'
+            ) as most_recent_dibels_composite_current,
+            lag(coalesce(dr.mclass_measure_standard_level, 'No Data'), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as most_recent_dibels_composite_prev_year,
+
+            lag(g.gpa_y1, 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as gpa_y1_prev_year,
+
+            coalesce(sr.days_suspended_oss, 0) as days_suspended_oss_current,
+            coalesce(sr.days_suspended_all, 0) as days_suspended_all_current,
+            lag(coalesce(sr.days_suspended_oss, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as days_suspended_oss_prev_year,
+            lag(coalesce(sr.days_suspended_all, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as days_suspended_all_prev_year,
+            coalesce(sr.referral_count_all, 0) as referral_count_current,
+            lag(coalesce(sr.referral_count_all, 0), 1) over (
+                partition by co.student_number order by co.academic_year asc
+            ) as referral_count_prev_year,
+        from {{ ref("int_extracts__student_enrollments") }} as co
+        left join
+            iready_pivot as ir
+            on co.student_number = ir.student_id
+            and co.academic_year = ir.academic_year_int
+        left join
+            dibels_recent as dr
+            on co.student_number = dr.mclass_student_number
+            and co.academic_year = dr.mclass_academic_year
+            and dr.rn_benchmark = 1
+        left join
+            gpa as g
+            on co.studentid = g.studentid
+            and co.schoolid = g.schoolid
+            and co.yearid = g.yearid
+            and {{ union_dataset_join_clause(left_alias="co", right_alias="g") }}
+        left join
+            {{ ref("int_reporting__referral_suspension_rollup") }} as sr
+            on co.student_number = sr.student_school_id
+            and co.academic_year = sr.create_ts_academic_year
+        where co.academic_year >= {{ var("current_academic_year") - 1 }}
+    )
+
+select *
+from roster
path: src/dbt/kipptaf/models/extracts/google/sheets/rpt_gsheets__mtss_rti.sql
user: login: anthonygwalters
body: The idea here was to get one row per kid for the current academic year only, so that filters will not need to be updated after current academic year is over. Multiple rows are needed above to so the LAG functions will work. 
created_at: 2025-04-22T19:37:08Z
author_association: MEMBER
path: src/dbt/kipptaf/models/reporting/intermediate/int_reporting__referral_suspension_rollup.sql
user: login: anthonygwalters
body: done
created_at: 2025-04-22T19:46:51Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,120 @@
+with
+    suspension_type as (
+        select penalty_name, 'ISS' as suspension_type,
+        from
+            unnest(
+                [
+                    'In School Suspension',
+                    'KM: In-School Suspension',
+                    'KNJ: In-School Suspension'
+                ]
+            ) as penalty_name
+
+        union all
+
+        select penalty_name, 'OSS' as suspension_type,
+        from
+            unnest(
+                [
+                    'Out of School Suspension',
+                    'KM: Out-of-School Suspension',
+                    'KNJ: Out-of-School Suspension'
+                ]
+            ) as penalty_name
+    ),
+
+    incidents as (
+        select
+            *,
+            case
+                when regexp_extract(category, r'^(.*?)\s*-\s*') in ('SW', 'SS', 'SSC')
+                then 'Social Work'
+                when
+                    regexp_extract(category, r'^(.*?)\s*-\s*') = 'TX'
+
+                    or category in ('School Clinic', 'Incident Report/Accident Report')
+                then 'Non-Behavioral'
+                when
+                    (
+                        regexp_extract(category, r'^(.*?)\s*-\s*') in ('T1', 'Tier 1')
+                        and regexp_extract(_dbt_source_relation, r'(kipp\w+)_')
+                        != 'kippmiami'
+                    )
+                    or (
+                        regexp_extract(category, r'^(.*?)\s*-\s*') in ('T4', 'T3')
+                        and regexp_extract(_dbt_source_relation, r'(kipp\w+)_')
+                        = 'kippmiami'
+                    )
+                then 'Low'
+                when regexp_extract(category, r'^(.*?)\s*-\s*') in ('T2', 'Tier 2')
+                then 'Middle'
+                when
+                    (
+                        regexp_extract(category, r'^(.*?)\s*-\s*') in ('T3', 'Tier 3')
+                        and regexp_extract(_dbt_source_relation, r'(kipp\w+)_')
+                        != 'kippmiami'
+                    )
+                    or (
+                        regexp_extract(category, r'^(.*?)\s*-\s*') = 'T1'
+                        and regexp_extract(_dbt_source_relation, r'(kipp\w+)_')
+                        = 'kippmiami'
+                    )
+                then 'High'
+                when category is null
+                then null
+                else 'Other'
+            end as referral_tier,
+        from {{ ref("stg_deanslist__incidents") }}
+    )
+
+select
+    dli.student_school_id,
+    dli.create_ts_academic_year,
+
+    count(
+        distinct if(dlp.is_suspension, dlp.incident_penalty_id, null)
+    ) as suspension_count_all,
+    count(
+        distinct if(
+            dlp.is_suspension and st.suspension_type = 'OSS',
+            dlp.incident_penalty_id,
+            null
+        )
+    ) as suspension_count_oss,
+    count(
+        distinct if(
+            dlp.is_suspension and st.suspension_type = 'ISS',
+            dlp.incident_penalty_id,
+            null
+        )
+    ) as suspension_count_iss,
+    sum(if(dlp.is_suspension, dlp.num_days, null)) as days_suspended_all,
+    sum(
+        if(dlp.is_suspension and st.suspension_type = 'OSS', dlp.num_days, null)
+    ) as days_suspended_oss,
+    sum(
+        if(dlp.is_suspension and st.suspension_type = 'ISS', dlp.num_days, null)
+    ) as days_suspended_iss,
+
+    count(distinct dli.incident_id) as referral_count_all,
+    count(
+        distinct if(dli.referral_tier = 'High', dli.incident_id, null)
+    ) as referral_count_high,
+    count(
+        distinct if(dli.referral_tier = 'Middle', dli.incident_id, null)
+    ) as referral_count_middle,
+    count(
+        distinct if(dli.referral_tier = 'low', dli.incident_id, null)
+    ) as referral_count_low,
+from incidents as dli
+left join
+    {{ ref("stg_deanslist__incidents__penalties") }} as dlp
+    on dli.incident_id = dlp.incident_id
+    and {{ union_dataset_join_clause(left_alias="dli", right_alias="dlp") }}
+left join
+    {{ ref("int_deanslist__incidents__custom_fields__pivot") }} as cf
+    on dli.incident_id = cf.incident_id
+    and {{ union_dataset_join_clause(left_alias="dli", right_alias="cf") }}
+left join suspension_type as st on dlp.penalty_name = st.penalty_name
+where dli.referral_tier not in ('Non-Behavioral', 'Social Work')
+group by all
path: src/dbt/kipptaf/models/deanslist/intermediate/int_deanslist__referral_suspension_rollup.sql
user: login: cbini
body: specify the group by cols
created_at: 2025-04-22T19:56:32Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,135 @@
+with
+    iready_long as (
+        select
+            student_id,
+            academic_year_int,
+
+            lower(subject) as subject,
+            concat(
+                most_recent_overall_relative_placement,
+                ' (',
+                most_recent_completion_date,
+                ')'
+            ) as iready_most_recent,
+        from {{ ref("base_iready__diagnostic_results") }} as ir
path: src/dbt/kipptaf/models/extracts/google/sheets/rpt_gsheets__mtss_rti.sql
user: login: cbini
body: trunk (and me) wants you to drop the alias
created_at: 2025-04-22T19:56:58Z
author_association: MEMBER

PR comments:
user: login: cbini
created_at: 2025-04-23T14:13:21Z
body: wow just skipping final review? kill me now. take a carving knife and stab me right here. It would hurt less than what you just did.
author_association: MEMBER
user: login: anthonygwalters
created_at: 2025-04-23T14:47:34Z
body: > wow just skipping final review? kill me now. take a carving knife and stab me right here. It would hurt less than what you just did.

@cbini 

Now wait a minute. I don't like that kind of talk. Now just stop it, it upsets me.
author_association: MEMBER