Skip to main content
Question

I want to calculate the number of cases in which each possible activity has reoccurred multiple times. How am I able to do this?

  • August 21, 2024
  • 3 replies
  • 44 views

In my output (OLAP) table I want to have each activity name from the activity table and then an overview of the number of cases in which that activity name has occurred. Then I want to get an overview of the number of cases in which that activity name has occurred two times, three times, or multiple times etc.

 

I know with MAX of INDEX_ACTIVITY_TYPE I can get the max occurrences of the activity name, but I do not seem to be able to find out how to use this in an OLAP formulation. Thanks in advance!

3 replies

mathijs.lende12
Level 3
Forum|alt.badge.img+11

Hi Jan,

 

I hope I understood your question correctly.

Hope this helps:

 

OLAP table

ACTIVITY_COLUMN:

"ACTIVITY_TABLE"."ACTIVITY"

 

COUNT_1:

SUM(

CASE WHEN

 INDEX_ACTIVITY_TYPE ("ACTIVITY_TABLE"."ACTIVITY") = 1

 THEN 1

 ELSE 0

 END

)

 

COUNT_2:

SUM(

CASE WHEN

 INDEX_ACTIVITY_TYPE ("ACTIVITY_TABLE"."ACTIVITY") = 2

 THEN 1

 ELSE 0

 END

)

 

COUNT_3:

SUM(

CASE WHEN

 INDEX_ACTIVITY_TYPE ("ACTIVITY_TABLE"."ACTIVITY") = 3

 THEN 1

 ELSE 0

 END

)

 

 

 

Result:

This should show an OLAP table with 1 row per activity and the number of cases where the number of times is the same as stated in the formula (1, 2, 3).


  • Author
  • Level 3
  • August 23, 2024

Great Mathijs, thank you!

 

That was indeed what I wanted to know! The only thing I still miss is how I can calculate the number of cases in which that activity occurred >=2 times. When I change the formula to >=2, I get the wrong count as then a case with 4 activity occurrences is counted as 3 instead of 1 (it counts the second occurrence, third occurrence and fourth occurrence all as one 'case'). Is there anyway to count only the distinct cases?

 

Thanks again!


  • Author
  • Level 3
  • August 23, 2024

And also when calculating the lead time for cases with exactly 1 occurrence of the activity I cannot use  INDEX_ACTIVITY_TYPE ("ACTIVITY_TABLE"."ACTIVITY") = 1 because then it will also consider cases with multiple occurrences. How can I then select ONLY cases with EXACTLY one occurrence of that activity versus distinct cases with more than one occurrence of that activity?