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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
samahiji
Frequent Visitor

Text from function

Hi,

I have defined a function and named E_Date to generate the short date formate (i.e 01-Nov-24) to be embedded in SQL in power query. However, I'm not sure why it return null!

= "01-"&Text.Start(Date.MonthName(DateTime.LocalNow()),3)&"-"&Text.End(Date.ToText(DateTime.Date(DateTime.LocalNow())),2)

 The output is exactly what I need (01-Nov-24), however it return nothing to embedded query.

 .... DATE  <=  '"&E_Date&"'...
4 REPLIES 4
Anonymous
Not applicable

Hi @samahiji ,

 

Pls has your problem been solved? If so, accept the reply as a solution. This will make it easier for the future people to find the answer quickly.

When embedding E_Date in your SQL query, ensure that the syntax is correct. For example:

let
    SQLQuery = "SELECT * FROM Table WHERE DATE <= '" & E_Date & "'"
in
    SQLQuery

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Oh--in that case just escape the single quote like this:

 

'' (that is two apostrophes).

 

So

"SELECT...FROM...

WHERE DATE <= ''"&E_Date&"''AND..."

 

Remember, that's an apostrophe escaping an apostrophe.

 

--Nate

Anonymous
Not applicable

Looks like you just need to remove those single quotes. So

 

"SELECT...FROM...

WHERE DATE <= "&E_Date&" AND..."

 

--Nate

The single quotes are required for the sql date to run. It returns error when removed.

I added the single quotes inside the function itself but it didn't work though.

 

However, creating parameter will solve the issue, but I need to make it dynamic.

= "'"&"01-"&Text.Start(Date.MonthName(DateTime.LocalNow()),3)&"-"&Text.End(Date.ToText(DateTime.Date(DateTime.LocalNow())),2)&"'"

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors