How to create a filed based on a condition