cancel
Showing results for
Did you mean:
Helper III

## Record only display last 3 years (complete cycles) value

Hi.

I have created a sample table below for reference.

I need to create a line chart. How can I create a measure to only display the last 3 years of records (complete cycles) from the current year?

Regards,

NickzNickz

.

1 ACCEPTED SOLUTION
Helper III

Based on your input and the available samples, I create the measure below to get the value.

``````Last 3 Years =

VAR _currentyear = YEAR(TODAY())
VAR _previousyear = SELECTEDVALUE(test_last3years[Year])
RETURN
SWITCH(
TRUE(),
_previousyear <= _currentyear -1 &&
_previousyear >= _currentyear -3,1,
0
)``````

Regards,
NickzNickz

7 REPLIES 7
Resolver II

Hi @NickzNickz ,

create a measure to determine the current year. You can use the TODAY() function to get the current date and extract the year from it

``Current Year = YEAR(TODAY())``

Now, create a measure that calculates the last 3 years from the current year. Let's name this measure "Last 3 Years"

``Last 3 Years = IF([Year] >= [Current Year] - 3 && [Year] <= [Current Year], 1, 0)``

Finally, use the "Last 3 Years" measure as a filter in your line chart visual. Set the filter to include only the records where the measure evaluates to 1.

Helper III

I have successfully created the measure for Year.

For measure #2, how can I get the column [Year] .... ?

Resolver II

For that, use the year column in your table===>  'Tablename'[year]

Helper III

Based on your input and the available samples, I create the measure below to get the value.

``````Last 3 Years =

VAR _currentyear = YEAR(TODAY())
VAR _previousyear = SELECTEDVALUE(test_last3years[Year])
RETURN
SWITCH(
TRUE(),
_previousyear <= _currentyear -1 &&
_previousyear >= _currentyear -3,1,
0
)``````

Regards,
NickzNickz

Resolver II

IF you want to use simplified code , you can use the below code :

``````Last 3 Years =
VAR _currentyear = YEAR(TODAY())
VAR _previousyear = SELECTEDVALUE(test_last3years[Year])
RETURN
IF(_previousyear >= _currentyear - 3 && _previousyear <= _currentyear - 1, 1, 0)``````

Helper III

Thank you for your help and ideas ... Really appreciate that ...

Helper III

I tried but couldn't find the table name.

Announcements

#### Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

#### Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

#### Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Top Solution Authors
Top Kudoed Authors