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.
I am new to Power BI.....
I added a custom column in the query editor and all I want to do is add a filter for last 30 days, last 90 days, last 180 days. I figured there would be 3 columns to do this so I am working on the first one.
if today()- [start date] <30 then 1 else 0
I have done this with the start date column being a date and with it being text and both throw an error "the name 'today' wasn't recognized. Make sure it's spelled correctly.
Any help on this is appreciated.
Solved! Go to Solution.
it looks like that IF statement compares Duration to Days
So try this instead...
= if Duration.Days(DateTime.Date(DateTime.LocalNow()) - [Date]) < 30 then 1 else 0
EDIT:
https://msdn.microsoft.com/en-us/library/mt253516.aspx
You have to compare the same Data Types
So the column in Red calculates the Days correctly but displays them as Duration
that's why the previous attempt was failing
all we did here is first convert the red column to days and then check - is it less than 30
Hope this helps!
You're mixing DAX with your M, try DateTime.LocalNow
Thanks for the quick response. I typed it in as
=if DateTime.LocalNow() - [Start Date]<30 then 1 else 0
*Start Date is a date data type*
I am now getting this error:
Expression.Error: We cannot apply operator - to types DateTime and Date.
Details:
Operator=-
Left=4/5/2017 10:44:15 AM
Right=1/2/2017
Try with little modification:
=if DateTime.Date(DateTime.LocalNow()) - [Start Date]<30 then 1 else 0
I am getting the following error with this formula.
=if DateTime.Date(DateTime.LocalNow()) - [Start Date]<30 then 1 else 0
Expression.Error: We cannot apply operator < to types Number and Duration.
Details:
Operator=<
Left=30
Right=93.00:00:00
I have changed the data type to date, date time for both columns, but still get errors. Is there an easier way to do this. I just want a 1 if less than 30 days ago from [Start Date] (which is 1/2/2017 in the column)
it looks like that IF statement compares Duration to Days
So try this instead...
= if Duration.Days(DateTime.Date(DateTime.LocalNow()) - [Date]) < 30 then 1 else 0
EDIT:
https://msdn.microsoft.com/en-us/library/mt253516.aspx
You have to compare the same Data Types
So the column in Red calculates the Days correctly but displays them as Duration
that's why the previous attempt was failing
all we did here is first convert the red column to days and then check - is it less than 30
Hope this helps!
Ok.
Use this in the Custom Column:
if Duration.Days(DateTime.Date(DateTime.LocalNow()) - [StartDate])<30 then 1 else 0
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
83 | |
70 | |
61 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |