Hi there: I need help creating these calculated fields (in Beast Model) where they change based on current year. I created this in EXCEL but am still learning SQL - any help would be much appreciated!
calculated fields | |
---|
cy | Sum `rtfs_amount` for each DISTINCT `Base Request ID`where `fsa_spending_year` is current year |
cy+1 | Sum `rtfs_amount` for each DISTINCT `Base Request ID`where `fsa_spending_year` is current year+1 |
cy+2 | Sum `rtfs_amount` for each DISTINCT `Base Request ID`where `fsa_spending_year` is current year + 2 |
cy+3 | Sum `rtfs_amount` for each DISTINCT `Base Request ID`where `fsa_spending_year` is current year +3 |
Here is SAMPLE data I am working with:
request_transactions_organization_payee_id | Base Request ID | rtfs_amount | fsa_spending_year |
---|
700 | 1 | $22,500.00 | 2023 |
700 | 1 | $22,500.00 | 2024 |
700 | 1 | $22,500.00 | 2025 |
800 | 2 | $1,000.00 | 2023 |
800 | 2 | $1,000.00 | 2024 |
800 | 2 | $1,000.00 | 2025 |
800 | 2 | $1,000.00 | 2026 |
800 | 2 | $1,000.00 | 2027 |
900 | 3 | $200.00 | 2023 |
900 | 3 | $200.00 | 2024 |
800 | 4 | $350.00 | 2024 |
700 | 5 | $1,450.00 | 2024 |
700 | 5 | $1,450.00 | 2025 |
700 | 5 | $1,450.00 | 2026 |
700 | 5 | $1,450.00 | 2027 |