Forum Discussion

kobkabnaja's avatar
kobkabnaja
Icon for Helper II rankHelper II
1 year ago
Solved

Use a variable on "Filters on this virtual"

Hi community,   I have a quick question about applying a filter to my Power BI dashboard. I want to display monthly data for only the past four years. Currently, I am using a filter at the visualiz...
  • hnguy71's avatar
    hnguy71
    1 year ago

    Hi kobkabnaja ,

    Because you're evaluating each year line by line, the current max item will always be equal to the selected item, therefore you'll get a true result always.

    This should work instead:

    Selected Years = 
    
    VAR _HowManyYrs = 4
    VAR _MaxYear = CALCULATE(MAX('DATE'[Year]), ALL('DATE'))
    RETURN
    IF( SELECTEDVALUE('DATE'[Year]) <= _MaxYear - _HowManyYrs, 0, 1)

     

    Then on your visual, don't forget to filter for where value is 1: