Skip to main content

Hi all,

Im struggling with the following problem.

The table structure is as follows:

Instance

|

Task

|

Instruction

image1165333 21 KB

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 didnt 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

@simon.wendl Instead of using 1 & 0 you can use the actual value to be returned and apply a distinct to it then the double entries should not be counted anymore. COUNT(DISTINCT CASE WHEN ... THEN real value ELSE ... END)

 

Best

Kevin


Hi Simon,

You almost got it. The logic is right, but you need to create an index to group by period and create an order then pull the max value of each.MAX(

INDEX_ORDER (

    "table"."JaNeinColumn" ,

    ORDER BY ( "table"."period" ASC) ,

    PARTITION BY ( "table"."period")

)

)

Best,

Gabriel


Reply