Forum Discussion

vani's avatar
vani
Helper I
10 years ago
Solved

Ignore filter year selection

Hello everyone,

 

Iam trying to ignore the selection of an certain year.

 

I've the following measure:

 

Grow Year -1 = CALCULATE(SUM('Inscrições'[Value]);FILTER('Inscrições';and(not('Inscrições'[Pais]="Portugal");'Inscrições'[Ano]=max('Inscrições'[Ano])-1)))

 

I think that should work, bue when i change of year, the figure become empty (on this case table im using a table).

 

I hope you guys can help me !

 

Thanks !

  • Alright, I think I understood you now. What you want is to show the previous year no matter what year is selected. For eg, if we are on 2016, you always want to show 2015 data, even if we select 2010 or 2012 or any other year on filter.

     

    1) Create a measure that will show the max year available in the fact table

    MaxYear=CALCULATE(MAX('Fact'[Year]), ALL('Fact'[Year]))

     

    2) Now make the measure as you want. Instead of hardcoding 2014, you can use the measure which will always return the max year available in fact, irrespective of the filter.

    test=CALCULATE(SUM('Fact'[Sales]), FILTER(ALL('Fact'[Year]), 'Fact'[Year]=[MaxYear]-1))

     

    Is this what you want? :)

10 Replies

  • SqlJason's avatar
    SqlJason
    Memorable Member

    Can you try splitting your filter statements?

     

    Grow Year -1 = CALCULATE(SUM('Inscrições'[Value]);FILTER('Inscrições';not('Inscrições'[Pais]="Portugal"));FILTER(ALL('Inscrições'[Ano]); 'Inscrições'[Ano]=max('Inscrições'[Ano])-1)))

     

    Just check the syntax as I am not used to the Non-US form of separators :)

     

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    I'm not the best with Spanish/Portuguese but I'm thinking that your filter for year (Ano) being set to equal MAX of Ano is the problem here. So, I'm thinking that unless the Ano you are selecting is the MAX of Ano - 1 in your table, your measure is going to be blank.

    • SqlJason's avatar
      SqlJason
      Memorable Member

      As Greg_Deckler said, if you just use Ano = max(ano -1), you will only see value for the year which is the max year - 1 and blank for everythign else. 

      Which is why I have included the ALL(Ano) to override the context of the year. Now you should be able to select any year, and the measure should show year -1 of the selected year.

      • vani's avatar
        vani
        Helper I

        I guys,

         

        That doesn't solve my problem. 

         

        When i select a year from the  slicer object , the table still become empty. 

         

        There is a way when i select year from the slicer object and the values remain the same(check formula above)

         

        Grow Year -1 = CALCULATE(SUM('Inscrições'[Value]);'Inscrições'[Year]=2014)

         

        The problem is that the year is "hardcoded" , and when i use  'Inscrições'[Year] = max('Inscrições'[Year]) , a error is shown " A function 'MAX' has been used in a True/False expression that is used as a table filter expression. This is not allowed."

         

        Thanks !