Skip to main content

I am aware of PQL that checks if activity A directly follows B. Can someone help me with PQL to check if first/last occurrence of A directly follows first/last occurrence of B?

Hi ​@Sony Shrestha

Not sure if I totally get what you would like to achieve, but I think you can do two checks per activity:

  1. Check if it is the first/last activity of that type
  2. Check if there is a direct follow between the two

To do, create a helping KPI:

‘KPI ‘FirstLastClassification’

CASE
WHEN INDEX_ACTIVITY_TYPE ( "activity_table"."activity_name" ) = 1
THEN 'First'
WHEN INDEX_ACTIVITY_TYPE_REVERSE ( "activity_table"."activity_name" ) = 1
THEN 'Last'
END

Then, Check if your events are true for this specific scenario:

CASE
-- perform checks on current event
WHEN "activity_table"."activity_name" = 'A'
AND KPI("FirstLastClassification") = 'First' -- Change to last if required
-- perform checks on next event
AND ACTIVITY_LEAD ( "activity_table"."activity_name" ) = 'B'
AND ACTIVITY_LEAD ( KPI("FirstLastClassification") ) = 'Last'
THEN 'Direct Follow'
ELSE NULL
END

When adding these formulas to a table, you would see for every activity if it is the first or last, and also if there is a direct follow for the situation you defined in the second KPI. 

 

I hope this helps! 

 

Best regards,

Jan-peter


Reply