Access Query Parameters in Python Notebook?

Hello -

Is there anyway to access query parameter selections from a Python Notebook?

i.e. I'd like to read the string value of the parameter and use that to update chart labels in the Python notebook.

Thank you,
Matt

6replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi Matthew !  This is possible. You need to add the parameter to your SELECT statement so the selected parameter is in the Python dataset.  Here's one example report that does this:

    https://modeanalytics.com/modeanalytics/reports/f86d4273987c

    Reply Like
  • Donna McGahan That's a wonderful hack, thank you!

    Reply Like
  • Matthew Isanuk Do you by any chance have your final queries to share? I have attempted to do something similar, but when I try and run a separate query just to load the parameter (as in the example) it errors out.

    Donna McGahan Any thoughts on the below as well?

    For more context, here is the query:

    SELECT {{customer}} AS customer_key;

    And here is the parameter:

    customer:
      type: select
      default: '* All Customers'
      options:
        values: CUSTOMER_KEY
        labels: CUSTOMER_KEY

    The specific error returned is:

    SQL compilation error:
    syntax error line 1 at position 9 unexpected 'All'.
    

    So, to my mind, it gets as far as replacing the {{customer}} parameter with '* All Customers' but then hiccups there, disliking something.

    I did try removing the "*" character as the default but that made no difference. I have tried with this query in the same query as the parameters, and also on its own. No difference.

    Reply Like
  • Robby ,

     

    Give this a try?  I think you need single quotes:

    SELECT '{{customer}}' AS customer_key;
    Reply Like
  • Donna McGahan Thank you!!!!!! AS ALWAYS you are so incredibly fast with responses. That worked!

    Reply Like
  • Awesome!  

    Reply Like
login to reply
Like3 Follow
  • 3 Liked by
  • 3 wk agoLast active
  • 6Replies
  • 110Views
  • 4 Following

Create A New Discussion

Share your thoughts