Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
76 | |
75 | |
56 | |
38 | |
34 |
User | Count |
---|---|
99 | |
56 | |
51 | |
44 | |
40 |