Where function in calculated field Quicksight

How to get a measure value using “Where” condition in a calculated filed in Quicksight? For example I want to calculate a “measure” for period = ‘Previous Year’
Expected Calculated field, For example → sum(sales) where year = ‘2022’. How can I achieve this?

You can do this with an if else.

sum(ifelse({year}='2022',{sales},0))

Or you can add filters to your visuals.

Thanks Max for the reply. I followed your suggestion and created a calc field like this to achieve the result sumIf({sales},contains({year}, “2022”))