Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

max year previous year doens't work with condition

Hello all,

I have a simple formula that sum sales for the max year (selected) and its previous one. The thing is that I have an 'if' condition before this formula as follows:

if( DimensionX='ABCD',

sum({$<[Year]={$(=Max(Year)),$(=Max(Year)-1)},[Type]={'yyy'}>}[Sales]).

Without the 'If' condition part, the formula works perfectly and when I select a year, it appears the sales for the year and previous year, but when I add the 'If' condition, if I select a year, the previous year doesn't appear and I need both years to appear.

Any advice??

Thanks in advance

1 Solution

Accepted Solutions
sunny_talwar

Can you check now

View solution in original post

6 Replies
sunny_talwar

Try this

If(Only({1} DimensionX) = 'ABCD', Sum({$<[Year]={$(=Max(Year)),$(=Max(Year)-1)},[Type]={'yyy'}>}[Sales]))

Anonymous
Not applicable
Author

I tried it before but its not working, when selecting a year the previous year doesnt appear.

sunny_talwar

Would you be able to share a sample where this doesn't work?

Anonymous
Not applicable
Author

Hello Sunny,

Here u have , it is a simple sample of my problem, so if  you have any doubt I will try to add more info,

Thanks in advance

sunny_talwar

Can you check now

Anonymous
Not applicable
Author

Hello Sunny,

I had to modify a little bit your expression because I need an If condition for each expression ( each expression is different for each dimension)  as follows:

if(Only(TOTAL <Dimension>{1}Dimension)='X', ...

If(Only(TOTAL <Dimension>{1}Dimension)='Y', ...

If(Only(TOTAL <Dimension>{1}Dimension)='Z', ...)))

and now it works!

Many thanks!