Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Display current year values when no filter is selected

Hi, i have a card showing me the number of contracts created by an insurance company. I have a year slicer which allows me to have the number of contracts of the selected year. I would like to show the number of contracts of the current year (2021) when any year is selected.

 

I've found this topic, which suggests to use this measure : 

Measure = 
var selected_year = IF(ISFILTERED('date'[year]),SELECTEDVALUE('date'[year]),YEAR(TODAY()))
return
IF(SELECTEDVALUE('Table'[year])=selected_year,1,0)

 

In fact, it does work when i display the name of the contracts but when i make de distinct count, the measure is like blocked and I don't know why ? 

Any suggestions ? 

 

Thank you for your help ! 

 

Here the link of the topic : https://community.powerbi.com/t5/Desktop/Show-current-year-data-if-no-filter-is-selected/td-p/1120364

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Anonymous , thank you for your answer. In fact, I have two tables one called "Flux" containing all my contracts (one row = one contract) and their creation year, the other is a calendar table. When I don't select any year, I would like to display the number of rows in my "Flux" table where the creation year = this year (now it would be 2021). I don't know how to achieve this with a dax measure.

     

    I tried something by creating 3 measures : 

    The first one returns me the number of rows in my table (with a distinct count)

    The second do the same thing but i specified that creation year = Year(Today())

    Finally in the third one i used the isfiltered function and then i check if the field used in the slicer is filtered you have to return the first measure otherwise the second. It is working very well when I select a year but when I don't select any year the number of rows displayed is not equal to the number of rows displayed when the year = 2021.

     

    Thank you for your help ! 

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Anonymous 

    How about return the distinctcount using a measure to return the desired result.

     

    Or share screen shot of what and where you are trying to acieve the result.

     

    And, Yes, measures are blocked when context cannot be established.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous , thank you for your answer. In fact, I have two tables one called "Flux" containing all my contracts (one row = one contract) and their creation year, the other is a calendar table. When I don't select any year, I would like to display the number of rows in my "Flux" table where the creation year = this year (now it would be 2021). I don't know how to achieve this with a dax measure.

       

      I tried something by creating 3 measures : 

      The first one returns me the number of rows in my table (with a distinct count)

      The second do the same thing but i specified that creation year = Year(Today())

      Finally in the third one i used the isfiltered function and then i check if the field used in the slicer is filtered you have to return the first measure otherwise the second. It is working very well when I select a year but when I don't select any year the number of rows displayed is not equal to the number of rows displayed when the year = 2021.

       

      Thank you for your help !