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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Chenz55
New Member

Filtering with dates

Hi,

 

I'm new to DAX queries and trying to use the below code although I keep getting an error.

 

I want to filter based on the last 2 years of data based on todays date.

My Date_Rd column is in a string format.  I keep getting an error for some reason.

 

Any help is greatly appreciated.

 

Thanks

 

EVALUATE
FILTER(
    'values',
    DATEVALUE('values'[Date_Rd]) >= TODAY() - 730
)

 

3 REPLIES 3
Anonymous
Not applicable

Hi @Chenz55 ,

What is the format of your [Date_Rd] column?

Try to convert it first. Here’s an example of how you can do this if your dates are in the format DD/MM/YYYY:

EVALUATE
FILTER(
    'values',
    DATEVALUE(
        RIGHT('values'[Date_Rd], 4) & "-" &
        MID('values'[Date_Rd], 4, 2) & "-" &
        LEFT('values'[Date_Rd], 2)
    ) >= TODAY() - 730
)

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

rubayatyasmin
Super User
Super User

hi, @Chenz55 

 

you can also use Now() instead of Today(). But ofcourse what ChielFaber suggested you can also use DATEDIFF to determine date differences. Here is the example code for you,

 

EVALUATE
FILTER(
'values',
DATEVALUE('values'[Date_Rd]) >= DATE(YEAR(NOW()) - 2, MONTH(NOW()), DAY(NOW()))
)

 

it should solve your issues for now. Also, please add the error message of screen shot here as well. 

 

rubayatyasmin_0-1689517080227.png

 

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


ChielFaber
Solution Supplier
Solution Supplier

Do you have the error message for us? 

Regarding date filtering. I myself would suggest using the DATEDIFF function:
https://learn.microsoft.com/nl-nl/dax/datediff-function-dax


Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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