Solved

Can I use the value from the dashboard filter in my sql derived table's WHERE statement?

  • 7 June 2022
  • 1 reply
  • 215 views

I have a dashboard with an organization filter on it and I am wondering based on the organization that users select, whether I can write something like this in my sql-derived table. Basically, each organization has a different max date and I want to only output the data that is from that max_date like so: 

 

Steps

** Dashboard user selects Organization A on the dashboard ** 

 

My sql-derived table: 

WHERE date(run_time) = (select max(date) from table where organization_name = {{ _filters['viewname.value'] }}) 

..where {{ _filters['viewname.value'] }})  equals Organization A, the org that the user selected in the dashboard filter.

^ the above is obviously not working but I hope it shows what I’m trying to do. 

icon

Best answer by Jimmy_Westman 10 June 2022, 15:06

View original

This topic has been closed for comments

1 reply

Hello!

Yes, this can be done. First you have to create a filter in the view file. This filter will appear in the explore just as any other dimension or measure. You can then apply a dashboard filter to this filter in the view.

By using this syntax:

WHERE
{% condition order_region %} order.region {% endcondition %}
you can then pass the value selected in the filter into the SQL of the derived table.

 

You can read about it here: https://docs.looker.com/reference/field-params/filter