Sum over a period with newest/latest values per period

Hi all,

I’m struggling with the following problem.

The table structure is as follows:
“Instance”
|
“Task”
|
“Instruction”

I want to calculate the sum of “Nein” and “Ja” over all Pay_Periods. However, I want to exclude the entries where I have double inputs for a month (CREATED_D differs slightly). So, I want to take the latest entry of a pay period (whether “Nein” or “Ja”) to be considered.

First, I tried to use
SUM ( CASE WHEN “Instruction”.“PROCESSOR_INPUT” = ‘Ja’ THEN ‘1’ ELSE ‘0’ END)
but I have no clue how to exclude the double entries / just consider the latest ones.

Also, I tried something with the following formula, however it didn’t work out
PU_MAX (“Task”,
“Instruction”.“Manual_INPUT”,
“Instruction”.“CREATED_D” =
PU_MAX(
“Task”,
“Instruction”.“CREATED_D”,
“Instruction”.“Manual_INPUT” IS NOT NULL
)
)

Hope the problem is well explained.

Thanks for you support!
Simon