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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Happy2023_05
Helper I
Helper I

How to show last 2 years data using measure?

Hi All,

I have date table with 3 yrs of data.When I want to bring the date to slicer I should see only 2 yrs of data. For eg slicer should show 2022 and 2021. Next year it should be 2023 and 2022. It should not be hard-coded in filters.

Automatically only 2 yrs value should be shown in slicer

Can we bring this in measure?

Any help is much appreciated

1 ACCEPTED SOLUTION

Hi,

Thank you for your feedback.

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

One of ways is to apply calculated column to report level filter pane.

 

Jihwan_Kim_0-1665571982341.png

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

one of ways to achieve this is to create a measure something like below, and put it into Visual Filter pane and set it up like below.

Please also check the attached pbix file.

 

Jihwan_Kim_0-1665568516529.png

 

Last two years measure: = 
VAR _currentyear =
    YEAR ( TODAY () )
VAR _previousyear = _currentyear - 1
RETURN
    IF (
        SELECTEDVALUE ( 'Year'[Year] ) = _currentyear
            || SELECTEDVALUE ( 'Year'[Year] ) = _previousyear,
        1,
        0
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you so much.But when I try to apply this measure for all pages I could not bring the measure to filter on all pages. Is there any other way to do it?

Hi,

Thank you for your feedback.

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

One of ways is to apply calculated column to report level filter pane.

 

Jihwan_Kim_0-1665571982341.png

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.