Forum Discussion

Jbigby's avatar
Jbigby
Regular Visitor
1 year ago

Snowflake Custom SQL query with parameters not returning results

Is there a way to dynamically filter a Snowflake custom SQL statement by using parameters via URL input? 

 

I am building Power BI report with the below requirements. The query works if I remove the last filters for parameters. However, I cannot bring in the entire dataset and need to be able to dynamically filter the query based upon the 2 parameters. The issues and current state details are below below. Please help.

 

Issues:

  • No results are returned
  • Cannot filter via URL
  • Do not see the option to Bind To Parameter

 

Requirements:

  • Power BI Pro
  • Use a service account for Snowflake connection.
  • No Power BI Gateway
  • DirectQuery Mode to bring in from Snowflake
  • The URL parameters need to filter the SQL query
    • entity_table is a column (ex: account)
    • object_id is a GUID (ex: 123abcd1a-1234-ab12-a123-000a1b2cde3f)
  • Don’t return any records unless a valid parameter is passed.
  • Embed into Dynamics CE from a Power BI Workspace, with dynamic filtering.
  • Ability to test functionality before handing off for embedding.

 

Current State:

  • Power BI report is published to Power BI workspace.
  • Connecting to Snowflake via Custom SQL query with CTEs, with filters for parameters at the end.
  • Includes parameters for par_entity_table and par_object_id, both with text format.
    • I've tried setting up both with and without a current value listed. Neither work.

 

Custom SQL query:

WITH cte_rpt_audit_v AS (

.... joins and aliases... 

)

SELECT *

  FROM cte_rpt_audit_v

 WHERE entity_table = ‘{{par_entity_table}}’

   AND object_id = ‘{{par_object_id}}’

 

Advanced Editor for Snowflake table:

 

Parameter Settings:

7 Replies

  • v-nmadadi-msft's avatar
    v-nmadadi-msft
    Community Support

    Hi Jbigby  ,
    Thanks for reaching out to the Microsoft fabric community forum.

    For a DirectQuery model table, the query must be a SELECT statement, and it can't use Common Table Expressions (CTEs) or a stored procedure.
    Source: Query folding guidance in Power BI Desktop - Power BI | Microsoft Learn

    This might be the reason for the error you are facing.

    If this post helps, then please consider Accepting as solution to help the other members find it more quickly and consider giving a KUDOS. Feel free to reach out if you need further assistance.
    Thank you

  • v-nmadadi-msft's avatar
    v-nmadadi-msft
    Community Support

    Hi Jbigby 

    May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

    Thank you.

     

  • v-nmadadi-msft's avatar
    v-nmadadi-msft
    Community Support

    Hi Jbigby ,
    As per Microsoft community guidelines, we will now proceed to close this thread to keep discussions focused and manageable. If you still need assistance, you're welcome to start a new thread in the community at any time.

    We appreciate your understanding and participation.
    Thank you