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

Get Fabric certified for FREE! Don't miss your chance! 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
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

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.