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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JemmaD
Resolver II
Resolver II

Use date filters on visual to bring in calendar years plus current incomplete year

Hi there 🙂

I know it is possible in query editor to do a 'last n calendar years' AND 'this year' but I want to achieve this in a visual.

So I can apply the last n calendar years, but it excludes the current incomplete year - and there is no option for an AND in the visual level filters pane. 

Is there a way to achieve this?

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

The inbuilt relative date filtering is pretty bad. The only way I've found to do this sort of thing in the past is to add a column to the date table which returns true or false depending on the logic you need, e.g.

Is in last 4 years =
var startYear = YEAR( TODAY()) -5
var endYear = YEAR(TODAY()) - 1
return 'Date'[Year] >= startYear && 'Date'[Year] <= endYear

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

The inbuilt relative date filtering is pretty bad. The only way I've found to do this sort of thing in the past is to add a column to the date table which returns true or false depending on the logic you need, e.g.

Is in last 4 years =
var startYear = YEAR( TODAY()) -5
var endYear = YEAR(TODAY()) - 1
return 'Date'[Year] >= startYear && 'Date'[Year] <= endYear

Because my Year is a text column I had to adapt the calculated column to:

Previous 4 Years =

VAR Year = VALUE ('Dates'[Year])
VAR startYear = YEAR ( TODAY ()) -3
VAR endYear = YEAR( TODAY ())
RETURN
Year>= startYear || Year = endYear

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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