# Case Statement with YTD

Options
Member
edited June 2023

Hi Folks,

I'm trying to derive this through Beast mode calculation.

Requirement: Case statement
Score 1 - If my error % is 0 - 75%

Score 2 - If my error % is 75.1% - 95%

Score 3 - If my error % is 95.1% - 100% (Includes 100)

Score 4 - If my error % is 100% (YTD)

Finding difficulty in writing a case statement for 'Score 4'.

Date fields are (Month and Year)

Question:
-When a person's error % for March 2023 is 100% but for Jan and Feb its less than 100% then the score should be 3 when filtered to March.
-If the person's error % is 100% for all months YTD then it the score should be 4 (Fixed).

Any help on how to derive this using beast mode please?

The calculation that I tried and didn't work is

Tagged:

• Coach
Options

@Rupak Instead of using a fixed function, you can add a case statement within your sums to find the current year totals like this:

```  when sum(case when `Year` = YEAR(CURRENT_DATE()) then `Count Yes` end)
/
sum(case when `Year` = YEAR(CURRENT_DATE()) then `Count Overall` end) > 0.99 then 4
```

• Coach
Options

What does your data look like and what kind of card are you outputting your result to? On your approach, you're only fixing by `Year` but if your data is meant to be broken down by person as well, you'll also need to include that in your fix function (otherwise it'll be the fixed of the entire universe and not for each person). I'd attempt changing the 3rd case statement to and move that as the first statement. Also does your data spans across multiple years and you're choosing which year to display? If so you won't be able to use the CURRENT_DATE() for the Beast Mode and would need to attempt a different approach.

```WHEN SUM(SUM(CASE WHEN `Year` = YEAR(CURRENT_DATE()) THEN `Count Yes` END) FIXED (BY `Person`))/SUM(SUM(CASE WHEN `Count Overall` = YEAR(CURRENT_DATE()) THEN `Count Yes` END) FIXED (BY `Person`)) = 1 THEN 4
```

• Coach
Options

@Rupak Instead of using a fixed function, you can add a case statement within your sums to find the current year totals like this:

```  when sum(case when `Year` = YEAR(CURRENT_DATE()) then `Count Yes` end)
/
sum(case when `Year` = YEAR(CURRENT_DATE()) then `Count Overall` end) > 0.99 then 4
```

• Coach
What does your data look like and what kind of card are you outputting your result to? On your approach, you're only fixing by `Year` but if your data is meant to be broken down by person as well, you'll also need to include that in your fix function (otherwise it'll be the fixed of the entire universe and not for each person). I'd attempt changing the 3rd case statement to and move that as the first statement. Also does your data spans across multiple years and you're choosing which year to display? If so you won't be able to use the CURRENT_DATE() for the Beast Mode and would need to attempt a different approach.
```WHEN SUM(SUM(CASE WHEN `Year` = YEAR(CURRENT_DATE()) THEN `Count Yes` END) FIXED (BY `Person`))/SUM(SUM(CASE WHEN `Count Overall` = YEAR(CURRENT_DATE()) THEN `Count Yes` END) FIXED (BY `Person`)) = 1 THEN 4