Skip to content

Commit

Permalink
Merge pull request #3496 from cal-itp/3483-review-ntd-validation-tables
Browse files Browse the repository at this point in the history
Bug Fix Display the organization name from last year if this year does not exist
  • Loading branch information
erikamov authored Oct 9, 2024
2 parents 5bdb453 + 7409951 commit 92ec3ab
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ WITH longform_this_year AS (
MAX(api_report_last_modified_date) AS max_api_report_last_modified_date
FROM {{ ref('stg_ntd_rr20_rural') }}
WHERE item LIKE ANY("%Directly Generated Funds%","%Formula Grants for Rural Areas%","Local Funds")
AND api_report_period = {{this_year}}
AND api_report_period = {{ this_year }}
GROUP BY organization, fiscal_year, total_expended, item
),

wide_this_year AS (
SELECT * FROM
(SELECT * FROM longform_this_year)
PIVOT(AVG(total_expended) FOR item IN ('FTA_Formula_Grants_for_Rural_Areas_5311', 'Other_Directly_Generated_Funds', 'Local_Funds'))
ORDER BY organization
),

longform_last_year AS (
Expand All @@ -42,18 +41,17 @@ longform_last_year AS (
MAX(api_report_last_modified_date) AS max_api_report_last_modified_date
FROM {{ ref('stg_ntd_rr20_rural') }}
WHERE item LIKE ANY("%Directly Generated Funds%","%Formula Grants for Rural Areas%","Local Funds")
AND api_report_period = {{last_year}}
AND api_report_period = {{ last_year }}
GROUP BY organization, fiscal_year, total_expended, item
),

wide_last_year AS (
SELECT * FROM
(SELECT * FROM longform_last_year)
PIVOT(AVG(total_expended) FOR item IN ('FTA_Formula_Grants_for_Rural_Areas_5311', 'Other_Directly_Generated_Funds', 'Local_Funds'))
ORDER BY organization
)

SELECT wide_this_year.organization,
SELECT COALESCE(wide_this_year.organization, wide_last_year.organization) AS organization,
wide_this_year.FTA_Formula_Grants_for_Rural_Areas_5311 AS FTA_Formula_Grants_for_Rural_Areas_5311_This_Year,
wide_this_year.Other_Directly_Generated_Funds AS Other_Directly_Generated_Funds_This_Year,
wide_this_year.Local_Funds AS Local_Funds_This_Year,
Expand Down

0 comments on commit 92ec3ab

Please sign in to comment.