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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

List In Parameter and ignore when null

I am using Power Query to pull data from SQL.  I have mutliple lists that are being created with the Text.Combine function I found here:  https://community.powerbi.com/t5/Desktop/Using-list-in-parameter-in-M-language/m-p/454178.  This works great but in my situation, i want to be able to ignore the related WHERE  IN if the parameter list is null.  I convert the Text.Combine to look like this in insure a null value parameter.

 

SKUList = if Text.Length(Text.Combine(#"tMultiSKU"[SKU List]))=0 then null else Text.Combine( List.Transform(#"tMultiSKU"[SKU List], each "'"&_&"'"), ",")

 

This appears to be assigning the variable properly for both null and the list filled in.  I tried to write a CASE WHEN within the WHERE clause to not search for this parameter if null.  Now that I added the CASE WHEN to the p.partnumber in(), I am getting an error that states An expression of non-boolean type specified in a context where a condition is expected, near ','.  

 

WHERE
p.itemstatusname in('"& ItemStatus & "')
AND CASE WHEN "&SKUList&" IS NOT NULL THEN p.partnumber in("&SKUList&") END

 

Is there a way around the error or a better way to ignore a null parameter?

3 REPLIES 3
lbendlin
Super User
Super User

This part

 

WHERE
p.itemstatusname in('"& ItemStatus & "')
AND CASE WHEN "&SKUList&" IS NOT NULL THEN p.partnumber in("&SKUList&") END

 

has an incomplete CASE statement (the ELSE part is not optional) and is missing the condition. Your case statement needs to either resolve to True/False, or you need to compare it to _something_

Anonymous
Not applicable

Thanks @lbendlin!  I am very new to this and did not know that the ELSE is required.  Does this comparsion CASE WHEN "&SKUList&" IS NOT NULL resolve the True/False?  Is there a way to do nothing with the ELSE portion of the CASE?  All I want to is a WHERE p.partnumber in (SKUList) when the SKUList variable contains multiple records like '123','456','789' and do nothing when SKUList is null.  p.partnumber in (SKUList) (without the CASE WHEN) works just fine when the variable contains values.  If the variable is left blank, I get 0 results but I want to see all results.

 

Any Thoughts?  Thanks again!

 add a dummy entry to your SKUList to make sure it is never null.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

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.