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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
CMN1BL
New Member

Referencing string in a variable in SQL statement

Hi,
I want to get a new data source, I only want to get the rows that have a matching value to what is in my Materials list (which is a text string). However, i'm not able to access the string of Materials via a variable in the SQL statement. 
Anyone know what I'm missing?

CMN1BL_1-1729080551542.png

 



1 ACCEPTED SOLUTION
BeaBF
Super User
Super User

@CMN1BL Hi! In this case, you cannot directly use it as a list in a raw SQL query within Power BI. However, you can make it as a step after the source step, like:
let
Source = Sql.Database("YourServerName", "YourDatabaseName", [Query = "SELECT * FROM YourTable"]),
// Use the existing 'Materials' variable
TrimmedMaterials = List.Transform(Text.Split(Materials, ", "), each Text.Trim(Text.Replace(_, "'", ""))), // Convert the string to a list and clean it up
FilteredRows = Table.SelectRows(Source, each List.Contains(TrimmedMaterials, [Material])) // Filter the rows
in
FilteredRows

BBF

View solution in original post

2 REPLIES 2
BeaBF
Super User
Super User

@CMN1BL Hi! In this case, you cannot directly use it as a list in a raw SQL query within Power BI. However, you can make it as a step after the source step, like:
let
Source = Sql.Database("YourServerName", "YourDatabaseName", [Query = "SELECT * FROM YourTable"]),
// Use the existing 'Materials' variable
TrimmedMaterials = List.Transform(Text.Split(Materials, ", "), each Text.Trim(Text.Replace(_, "'", ""))), // Convert the string to a list and clean it up
FilteredRows = Table.SelectRows(Source, each List.Contains(TrimmedMaterials, [Material])) // Filter the rows
in
FilteredRows

BBF

Thank you BBF!🙏

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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