Parameters in SELECT clause

Hello everyone. Is it possible to use query parameters in the SELECT clause of the SQL query? E.g. a user selects from a dropdown list whether he wants the sum, count or average value of a column? Something like dynamic measures in PowerBI

Hi @MusicMaker1337, I’m not familiar with PowerBI, but it should be possible to do basically anything with Parameters :slightly_smiling_face:. The SELECT with a Dropdown Parameter should work for the case you mentioned:

SELECT {{dropdown-parameter}}(column) FROM example

For more robust options using a Dropdown you can explore a Query Based Dropdown and create a Query with predefined options. It’s also possible to use a CASE statement to create different behaviors based on the parameter value:

         WHEN '{{param}}' = 'Option A' THEN sql_function1()
         WHEN '{{param}}' = 'Option B' THEN sql_function2()
         ELSE sth_else()
FROM example

Wow! That’s super cool, thank you so much for your reply!

I have setup extensive use of parameter using drop downs global to dashboards, driving multiple charts. It is straightforward to do and when you add the widgets to the dashboard you can make the parameters global, as long as names the same across different queries

You can do this even if the names don’t match. It’s discussed in our docs.