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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
saddam_hussain8
Frequent Visitor

Dynamic Parameter is not working with the slicer which have single quotes in the items like: ABC'S

Hi Team,

I am using dynamic parameter by following the microsoft doc. Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Docs

 

Using the document I have bing the parameter with the slicer that contains the values like: ABC, XYZ, PQR and also like: ABC's, XYZ's, PQR's.

I have successfully created the report and it is working fine with values like: ABC or PQR or XYZ

but when I am selecting XYZ's  from slicer the SQL statement is not working properly.

 

Below is the Power Query script: Here the  Para_ColumnName is a Parameter created to Bind the slicer.

 

let
//===================================================================================PART 1=======================================================//
selected_ColumnName = if Type.Is(Value.Type(Para_ColumnName), List.Type) then
Text.Combine({"'", Text.Combine( Para_ColumnName , "','") , "'"})
else
Text.Combine({"'" , Para_ColumnName , "'"}),

selectAll_ColumnName = if Type.Is(Value.Type(Para_ColumnName), List.Type) then
List.Contains(Para_ColumnName, "__SelectAll__")
else
false,
//===========================================================================================================================================//
All_ColumnName = if selectAll_ColumnName or selected_ColumnName="'ABC'" then "A" else "B",

//===========================================================================================================================================//
FinalQuery = if All_ColumnName ="A" then Source else Source1,
//=====================================================================================PART 2========================================================//
Source = Value.NativeQuery(Snowflake.Databases("","",[Role=""]){[Name=""]}[Data],
"
SELECT TOP 1000

List of Columns


FROM DBNAME.SCHEMANAME.TABLENAME
", null, [EnableFolding=true]),

//============================================================================================================================================//

Source1 = Source = Value.NativeQuery(Snowflake.Databases("","",[Role=""]){[Name=""]}[Data],
"
SELECT

List of Columns

FROM DBNAME.SCHEMANAME.TABLENAME

WHERE COALESCE (TRIM(UPPER(ColumnNAME)),'NA') IN ("&selected_ColumnName&")

", null, [EnableFolding=true]),

#"Removed Duplicates" = Table.Distinct(FinalResult)
in
#"Removed Duplicates"

 

 

1. When I Apply the slicer with values like:ABC or XYZ then this query works fine.

but when I use values like: XYZ's or ABC's then it gives me error

 

2. I have find the issue also, that the where clause is failed to escape the single quotes 

WHERE COALESCE (TRIM(UPPER(ColumnNAME)),'NA') IN ("&selected_ColumnName&")

 

3. can you please guide me on how can i make changes  in PART1 that can help to escpae the single quotes.

 

4. I have written below script to escape but its not working and giving error: which states, "Can not Conver the TYPE LIST to TYPE TEXT"

 

Single_quotes = if Text.Contains(Para_ColumnName,"'") then Text.Replace(Para_ColumnName,"'","\'") else Para_ColumnName,

 

But I dont know How to use Single_quotes in PART ONE.

 

 

 

 

 

2 ACCEPTED SOLUTIONS
v-yanjiang-msft
Community Support
Community Support

Hi @saddam_hussain8 ,

Please see if it ran into the limitations.

Best Regards,
Community Support Team _ kalyj

View solution in original post

Hi @saddam_hussain8 ,

Glad you solved the problem by yourself! Would you like accept your workaroud as solution? Then more people who have the same requirment will find the solution quickly and benefit here, thank you!

 

Best Regards,
Community Support Team _ kalyj

View solution in original post

3 REPLIES 3
saddam_hussain8
Frequent Visitor

I have figure out the suggestion as below:

selected_ColumnName = if Type.Is(Value.Type(Para_ColumnName), List.Type) then
Text.Combine({"'", Text.Combine( List.Transform(Para_ColumnName,  each Text.Replace(_,"'","\'")   , "','") , "'"})
else
Text.Combine({"'" , Text.Replace(Para_ColumnName ,"'","\'") , "'"}),

Hi @saddam_hussain8 ,

Glad you solved the problem by yourself! Would you like accept your workaroud as solution? Then more people who have the same requirment will find the solution quickly and benefit here, thank you!

 

Best Regards,
Community Support Team _ kalyj

v-yanjiang-msft
Community Support
Community Support

Hi @saddam_hussain8 ,

Please see if it ran into the limitations.

Best Regards,
Community Support Team _ kalyj

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors
Top Kudoed Authors