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

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.