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
bdehning
Post Prodigy
Post Prodigy

Need Measure to only show last 3 Years of Data

Here is a Power Bi Report.   Can someone create a measure I can use as a filter to show the last 3 years for any customer.  Customers are selected from Slicer on Selection Page which populates Page 1 columns.    

 

https://drive.google.com/file/d/1icSIA3aShqN3Ddb2p5WFO2vManfgfJhu/view?usp=drive_link

 

 

1 ACCEPTED SOLUTION

Here is the File that I did get to work.  I took Last3YearsFilter below and put it in ChatGPT and got the measure corrected.   

https://drive.google.com/file/d/104cWzIh7ei2zwQzFjXR1LkFAy6odeE7X/view?usp=sharing

 

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

I cannot understand your question.  Show the expected result very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Here is the File that I did get to work.  I took Last3YearsFilter below and put it in ChatGPT and got the measure corrected.   

https://drive.google.com/file/d/104cWzIh7ei2zwQzFjXR1LkFAy6odeE7X/view?usp=sharing

 

bdehning
Post Prodigy
Post Prodigy

I have not received a valid measure yet.   

HarishKM
Memorable Member
Memorable Member

@bdehning Hey,
you can use below measure 

Last3YearsFilter =
VAR MaxYear = MAX(CustomerTable[Year]) -- Get the maximum (most recent) year selected or available
VAR Last3Years = MaxYear - 3 -- Calculate the year that is 3 years before the most recent year
RETURN
IF (
CustomerTable[Year] >= Last3Years && CustomerTable[Year] <= MaxYear, -- Filter for the last 3 years
1, -- Return 1 if the year is within the last 3 years
0 -- Return 0 otherwise
)

 

If you use aboce measure then you will get 3 year worth record when you select 1 in filter.

Thanks
Harish M
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query

I put this in as Measure  

Last3YearsFilter =
VAR MaxYear = MAX('Table'[Year]) -- Get the maximum (most recent) year selected or available
VAR Last3Years = MaxYear - 3 -- Calculate the year that is 3 years before the most recent year
RETURN
IF (
'Table'[Year] >= Last3Years && 'Table'[Year] <= MaxYear, -- Filter for the last 3 years
1, -- Return 1 if the year is within the last 3 years
0 -- Return 0 otherwise
)

But I get where the two [Year] are bold below    A single value for column 'Year' in table 'Table' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

'Table'[Year] >= Last3Years && 'Table'[Year] <= MaxYear, -- Filter for the last 3 years
rajendraongole1
Super User
Super User

 

Hi @bdehning - as per the shared pbix file, there is no last three years data. i have created a measure plesae check added in visual filter too. 

rajendraongole1_0-1744962680796.png

Show Last 3 Years =
VAR CurrentYear = YEAR(TODAY())
RETURN
IF(
    MAX('table'[Year]) >= CurrentYear - 2,
    1,
    0
)
 
 
Please find the attached pbix file.
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





That is why I need a measure.  There is 3 years or more of data but most are not within the last 3 calendar years.  

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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