Skip to content

Commit

Permalink
Display the organization name from last year when the organization do…
Browse files Browse the repository at this point in the history
…es not exist this year

[#3483]
  • Loading branch information
erikamov committed Oct 9, 2024
1 parent 5bdb453 commit 7409951
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 7409951

Please sign in to comment.