Tableau error "Expression is too complex"
If you go hard on Tableau with different, nested and recursive Calculated Fields (functions), you probably sooner or later encounter the Tableau error "Expression is too complex."
When does this error occur? In my case, it occurred when a function was based on too many other functions. I got the following error in Tableau:
Those who have studied computer science know this as a Big O problem which refers to time and space complexity. In short, the function is too complex that too many resources and more importantly, too much time is required to return a result. Simplified, if Tableau has to check 100,000 rows 100,000 times to calculate a function, it might break (cause an error).
In my case, the function was checking another function. A recursive function calls itself. In rough terms, the idea of a recursive function is: Solve a problem of type X by writing a recursive function f(): 1. Break the original problem of type X into one or more smaller problems of type X. 2. Within f(), call f() on each of the smaller problems. 3. Within f(), piece together the results of (b) to solve the original problem. Now a simple IF-THEN-ELSE function solves a problem recursively too. But if there are too many functions nested within the IF-THEN-ELSE function, things might break. What's the simples solution? If you're at this complexity level, your workbook tends to slow down anyway so it might be a good idea to move some of the functions to Tableau Prep. By moving some of the workloads to Tableau Prep you should be able to solve the "Expression is too complex" problem and gain a faster workbook. Good luck! Franco