You can define a layer variable as it's explain in Nyalldawson blog.
Then use the variable name with @ decorator in Calculator.
For exemple :
- Let's define the
column_name variable in
layer properties > variables panel to a real column name of your layer.
- Then in Calculator I set the conditional code with this new variable (like @Chrisl show in his answer).
For your next layers you have to create and define again the variable in layer properties but only once in this place.
As you can see in your calculator when you use the exact same code as the precedent one, the variable change the value :
Why use layer variable than Global or Project variable ?
Because in you case you can define once the column_name variable and keep it as long as you want even if you define in another layer the same column_name variable.
If you use a project or global variable, the variable is define for all your layers but you need to redefine the value each time you need to perform your code (not recommended in your case)