Count number of times activity is followed by activity X



We would like to replicate the ‘directly preceded by’ list in the process explorer, i.e., we have a list of activities and their number of occurrences and would like to add a KPI/column that counts how often this activity was directly followed by a fixed activity X.

How could I achieve this? Match_activities / Match_process does not allow for variable activity references (i.e. the current row).


Never tried it myself for your case, however if you are on Celonis 4.3+ look into new SOURCE/TAGRET PQL function.

1 Like

Hi Nikolai,

Thanks for the pointer. Source/Target are not listed in the PQL list (in 4.4) so I did not know of their existence.

Since it took me some time to get my head around it’s usage, here is how I applied it:
Add add a dimension as follows:
Then add a KPI column as follows:


I do get slightly different results for some activities, while for others I get the same numbers as in the process explorer stats. Will post here when I figure that one out.

1 Like

Hi Joos,

sorry for the very late response on this one, but maybe it’s still relevant.

You are very close to the solution! The reason why you (probably) get different numbers as in the process explorer component is that, if your target activity occurs multiple times in a case, you count that as many times, whereas in the process explorer stats, the case count (number of distinct cases) is shown if you selected the case count KPI.
The numbers should match if you switch to “Activity frequency” in the Process explorer.

In order to replicate the Process Explorer stats in “Case frequency”-mode, you can leave the SOURCE-Dimension, and add another dimension
which counts the distinct cases for each target activity.
Now we need to add the restriction that the target activity should be a fixed activity. For that, simply add a component filter:

One more remark and another possible reason for numbers that don’t match: In the filter (or in your CASE WHEN condition), you use LIKE instead of “=”. If no wildcards are contained in the string (as in your case), leading and trailing “%”-Wildcards are assumed, and the comparison is not case sensitive. So if this is not what you want, you should use “=” instead of LIKE.

Best regards


Thanks, helped me, and hopefully also others (in the future) :slight_smile:

1 Like