Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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
)
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
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.
Proud to be a Super User!
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
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 63 | |
| 55 | |
| 42 | |
| 41 | |
| 23 |
| User | Count |
|---|---|
| 171 | |
| 136 | |
| 119 | |
| 79 | |
| 54 |