# Multiple collection of terms

As the title suggests, I am interested in how to perform multiple collection of terms. This means that for a given expression a*x*b + c*x^2*d+a*x*k, I want to collect first in powers of x and for each factor of of a power of x to collect again in terms of another variable. In the previous example this translates to (a(b+k))*x+c*d*x^2. Any ideas?

• Doesn't Collect[expr, {x, a}] do what you want? – Carl Woll Mar 20 '19 at 14:50

myexpression//Collect[#,{myoutermostparameters},Collect[#,{myinnermostparameters}]&]&