So what i am trying to achieve here is , I have historical data eg (2016 ,2017) But i want to display my visualization by latest year data . In order to achieve that i created a variable Max Year which store maximum year value . By comparing that variable with my field Year to date i want to do my calculations. , if i try writing it using Set analysis it will work . I need help to write my code using set analysis.
Set Analysis is for more efficient filtering - its not a replacement for an If statement such as your expression. Your If is a branching If rather than a filter. You could kludge something together using a set expression but is unlikely to perform better and it certainly won't be simpler or more intuitive than a properly structured nested if.
I put the Num() outside the Sum() statements. It does nothing inside the Sum().