Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Function within power query

Hi All!

 

This is my 1st post.

 

So...I've this query (it works well):

let
Source = Sql.Database("Server123", "abc"),
dbo_xyz = Source{[Schema="dbo",Item="xyz"]}[Data],
#"Accepted equals 0" = Table.SelectRows(dbo_xyz, each [Accepted] = 0),
#"Changed date/time to date" = Table.TransformColumnTypes(#"Accepted equals 0",{{"StartDay", type date}}),
#"StartDate before today" = Table.SelectRows(#"Changed date/time to date", each [StartDay] < DateTime.Date(DateTime.LocalNow()))
in
#"StartDate before today"

 

What I want to do is instead of putting "DateTime.Date(DateTime.LocalNow()))" is to put my function Today, which is pretty much the same code:

() =>
let
Source = DateTime.Date(DateTime.LocalNow())
in
Source

 

I try to learn something, but when I do something like:

#"StartDate before today" = Table.SelectRows(#"Changed date/time to date", each [StartDay] < Today)

 

I gain an error power bi cannot compare function with date...I get it, I need somehow to force m query to return result of Today instead of comparing Today, but I don't know how...I tried as well Function.Invoke but it needs 2 parameters (function and arguments, in my case it's very simple function with no args). Is it even possible? Is my fucntion missing something?

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

Normally you have to call the function with (), so Today().

 

To test this function, you should add a column using Today(). That way you can prove that the function works before using it in a comparison

View solution in original post

1 REPLY 1
HotChilli
Super User
Super User

Normally you have to call the function with (), so Today().

 

To test this function, you should add a column using Today(). That way you can prove that the function works before using it in a comparison

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.