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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
arpost
Post Prodigy
Post Prodigy

Is it possible to create a query from text?

I have a scenario where I need to generate a dynamic query and wondered if it is possible to do so by "creating" a query from text.

 

For example, if I had a text field that contained the following:

let
    Source = 1 = 1
in
    Source

could that then be executed as a query somehow?

arpost_0-1636500764736.png

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Yes.  You can use Expression.Evaluate("M expression") for that.

Expression.Evaluate - PowerQuery M | Microsoft Docs

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

Looks like you are missing the let and in parts of your query inside your Expression.Evaluate.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


That did the trick! It's a bummer the applied steps aren't listed using this method, but the method is great just the same. Appreciate it!

mahoneypat
Microsoft Employee
Microsoft Employee

Yes.  You can use Expression.Evaluate("M expression") for that.

Expression.Evaluate - PowerQuery M | Microsoft Docs

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Very cool! Didn't know about that function, @mahoneypat. Can this handle more complex queries? I keep getting an error when I try something like the following:

 

= Expression.Evaluate(    "Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(""i45WclTSUTI0MFCK1YlWcgKyjaBsZyDbGMSOBQA="", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Value = _t]),
    #""Changed Type"" = Table.TransformColumnTypes(Source,{{""Name"", type text}, {""Value"", Int64.Type}}),
    #""Filtered Rows"" = Table.SelectRows(#""Changed Type"", each ([Name] = ""B""))""""")

Here's the original in the Advanced Editor:

 

arpost_0-1636507251114.png

and here's the original code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0MFCK1YlWcgKyjaBsZyDbGMSOBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Value", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Name] = "B"))
in
    #"Filtered Rows"

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.