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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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 Specialist
Solution Specialist

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



[Tip] Keep CALM and DAX on.
[Solved?] Hit “Accept as Solution” and leave a Kudos.
[About] Chiel | SuperUser (2023–2) |

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.