Forum Discussion
Query editor: How to sort a list of dates into either before/after 7 days in the past
- 4 years ago
Hello Rob! This will do the trick...
First add a custom column named Days Elapsed. You can click Add Custom Column and then paste this into the editor:
Number.From(Date.From(DateTime.FixedLocalNow()))- Number.From([Next Inspection Date])Explanation: Number.From is converting the date into a number and comparing it the numeric version of today's date.
After you add this column you need to change the type to a number. You can either click on the column and change the type (to whole number) using the menu buttons, or you can look in the formula bar and add this little bit of text to the end. See the text in the red box below. This prevents adding another step to the query just to set the type.
Then Add New Column > Overdue Status > paste this into the editor:
if [Days Elapsed] > 7 then "Overdue" else "Ok"This time change the type to text (in the formula bar).
You don't have to create a separate column for the Days Elapsed, however, if you do, you will be able to see the overdue status and also how many days each is overdue by.
Here are the two lines of complete script.
AddDaysElapsed = Table.AddColumn(SourceTable, "Days Elapsed", each Number.From(Date.From(DateTime.FixedLocalNow()))- Number.From([Date]), Int64.Type), AddOverdueStatus = Table.AddColumn(AddDaysElapsed, "Overdue Status", each if [Days Elapsed] > 7 then "Overdue" else "Okay", type text) - 4 years ago
You're really close!
You just need to write DateTime.LocalNow() with the parentheses.
Hi jennratten,
Thank you so much for taking the time to not only fix my error but actually improve the method! Really appreciate it. Having a days elapsed column is actually very helpful. Have a good day 🙂
Best wishes, Rob
You are very welcome! You too!