Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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.
Solved! Go to Solution.
Hi @saddam_hussain8 ,
Please see if it ran into the limitations.
Best Regards,
Community Support Team _ kalyj
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
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
Hi @saddam_hussain8 ,
Please see if it ran into the limitations.
Best Regards,
Community Support Team _ kalyj
Check out the July 2025 Power BI update to learn about new features.