Show only 2024 costs

PJG
PJG Member

My usual disclaimer: I am not a programmer, and usually need an ELI5 for this :)

I have a version of this code working that is intended to show the total PlannedCosts when summing the 5 FinancialCategoryName types I have listed. Basically the same thing without the YEAR(Month,2024) AND piece. That works.

Now I'm trying to create a new version per below where it only shows the costs which occur in 2024, but it's still showing costs from all years. Can anyone help me understand why? Maybe I'm using the wrong function?

(sorry, don't know how to paste into the forum and keep the backticks)

CASE
WHEN YEAR(Month,2024) AND FinancialCategoryName='CAPEX - External IT Resource' THEN PlannedCost
WHEN YEAR(Month,2024) AND FinancialCategoryName='CAPEX - Internal IT Resource' THEN PlannedCost
WHEN YEAR(Month,2024) AND FinancialCategoryName='CAPEX - Hardware' THEN PlannedCost
WHEN YEAR(Month,2024) AND FinancialCategoryName='CAPEX - Software License' THEN PlannedCost
WHEN YEAR(Month,2024) AND FinancialCategoryName='CAPEX - Travel & Expense' THEN PlannedCost
END

My dataset has a column called Month with values formatted as Dec 1, 2025 12:00:00 AM.

Best Answer

  • MichelleH
    MichelleH Coach
    Answer ✓

    @PJG You should be able to replace YEAR(Month,2024) with YEAR(Month) = 2024 to get the results you need since the YEAR function returns the year of the date field in parenthesis and you only want to consider rows where the year is 2024.

Answers

  • MichelleH
    MichelleH Coach
    Answer ✓

    @PJG You should be able to replace YEAR(Month,2024) with YEAR(Month) = 2024 to get the results you need since the YEAR function returns the year of the date field in parenthesis and you only want to consider rows where the year is 2024.

  • PJG
    PJG Member

    Hi @MichelleH perfect, thank you!