Hello everyone,
I hope you can help me understand the difference between the two PQL functions CASE WHEN and STATIC CASE WHEN.
I can't find the difference using the documentation, and unfortunately, I couldn't find any content about it in the forum either. I would really appreciate your help and hope someone can explain it.
Thank you for your support!
Best regards,
Robert
Hi Robert!
To put it simply, it comes down to performance and efficiency.
-
CASE WHEN is DYNAMIC. It checks every single row because the result can change based on each individual event or activity. It's flexible but can be slower on big datasets.
-
STATIC CASE WHEN checks just once at the beginning because the condition won't change for each row. it stays the same across your query. This makes it faster and more efficient when using fixed or preselected criteria.
Examples:
CASE WHEN
Imagine you want to classify each individual purchase order based on its total amount:
CASE WHEN "Order Amount" > 10000 THEN 'Large Order' WHEN "Order Amount" BETWEEN 5000 AND 10000 THEN 'Medium Order' ELSE 'Small Order' END
This checks every single purchase order separately, labeling each order differently based on its amount.
STATIC CASE WHEN
suppose your dashboard has a dropdown selection where the user selects a KPI type to display. This selection doesn't change per row, it's the same for the entire dashboard:
STATIC CASE WHEN <%= user_selection %> = 'Delivery Time' THEN "Average Delivery Time" WHEN <%= user_selection %> = 'Cost' THEN "Average Cost per Order" ELSE "Total Orders" END
This checks just once, deciding which KPI is shown across the whole dashboard based on the user's selection before running the analysis.
Hope this helps.
Hello Sverre,
that was an excellent explanation that helps me a lot.
I appreciate the effort you put into it.
Thank you very much for that!
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.