Forum Discussion
Power Query Current Date Filter
- Anonymous9 years ago
Power Query does not use DAX formulas. It has its own language. TODAY() is not a valid formula in that language.
Also that dialog box will only allow literal date values, not formulas that evaluate to a date. But you can get past that. Type some date into that box and hit OK. It doesn't matter what date you enter because you're just using it to get out of the dialog box with a valid formula, after which you're going to replace it. After you hit OK look up at the formula bar for the step you just inserted. You should see something like:
= Table.SelectRows(#"Name of Previous Step", each [VALIDTO] <= #datetime(2016, 9, 12, 0, 0, 0))
Replace the end of that formula with DateTime.LocalNow() which is the Power Query nearest equivalent to TODAY()*.
= Table.SelectRows(#"Name of Previous Step", each [pafo_EstimatedEndDate] <= DateTime.LocalNow())
...or you could just go to the advanced editor and type in that step by hand if you know how to hand-code a new step.
*Technically it returns a Date/Time value, where TODAY() returns a Date value. The literal closest to TODAY() is Date.From(DateTime.LocalNow()) which you should use rather than DateTime.LocalNow() alone if the column you're filtering is already a plain date type rather than date/time.
Power Query does not use DAX formulas. It has its own language. TODAY() is not a valid formula in that language.
Also that dialog box will only allow literal date values, not formulas that evaluate to a date. But you can get past that. Type some date into that box and hit OK. It doesn't matter what date you enter because you're just using it to get out of the dialog box with a valid formula, after which you're going to replace it. After you hit OK look up at the formula bar for the step you just inserted. You should see something like:
= Table.SelectRows(#"Name of Previous Step", each [VALIDTO] <= #datetime(2016, 9, 12, 0, 0, 0))
Replace the end of that formula with DateTime.LocalNow() which is the Power Query nearest equivalent to TODAY()*.
= Table.SelectRows(#"Name of Previous Step", each [pafo_EstimatedEndDate] <= DateTime.LocalNow())
...or you could just go to the advanced editor and type in that step by hand if you know how to hand-code a new step.
*Technically it returns a Date/Time value, where TODAY() returns a Date value. The literal closest to TODAY() is Date.From(DateTime.LocalNow()) which you should use rather than DateTime.LocalNow() alone if the column you're filtering is already a plain date type rather than date/time.
- Promethes_29 years agoHelper II
This is exactly what I was looking for! I understood it uses M language but didn't realize you couldn't type the formula into the dialog box (TODAY() was just an example, I had tried DateTime.LocalNow() but that didn't work either). I am going to request this functionality to be added as it would seem more intuitive and user friendly to be able to build it on the fly rather than the solution you've provided.
Thank you very much for this helpful information!
- v-haibl-msft9 years agoMicrosoft Employee
You can add this idea on ideas site. And if KHorseman’s solution is exactly what you are looking for, you can mark his answer as solution to close this thread.
Best Regards,
Herbert
- Promethes_29 years agoHelper II
Done and Done! Thank you again!
- Anonymous6 years agoNot applicable
hi i am looking get data between 91-180, 181-270, 271-365 days from the current date. could you please help in doing so. looking for something similar to "in the previous...days" function would really appreciate the help
- KervBruce3 years agoAdvocate I
Hi, This solution does not seem to work for me as I get the following error:
- KervBruce3 years agoAdvocate I
No, ignore me I'm being dim. If course you cant compare Date with DateTime. I changed the Date field to DateTime and presto!
- Lawrenceiow2 years agoAdvocate I
That's great, thank you this worked for me. It does seem strange to me that we have IsInCurrentDay but not IsBeforeCurrentDay, I suppose they can't think of everything 🙂
- ReneeCrozier1 year agoRegular Visitor
I have been trying to figure this out for a while now. Thank you for making it so easy to figure out and understand!