Multiple questions

Let's say I want to create multiple questions each of which will be the same but with the different "WHERE" conditions like
WHERE city='Moscow'
or
WHERE city='Berlin' etc.
I don't want to do this manually it's a stupid and long process. How I can do this fast?
These questions are written in SQL btw

Basically, I want to create the same graph for each city and to be able to manage access to it so one city's business users won't be able to see other city's graphs

Hi @beyondfire94
Have you considered using Snippets?
https://www.metabase.com/docs/latest/users-guide/sql-snippets.html

@flamber
They don't change anything. I have 15 questions and 10 cities which means that I have to copy-paste and change a city name in a query 150 times then saving them 150 times in separate folders etc. This is a ton of stupid mechanical clicking.
Is there any way to do this faster?
Or can I duplicate a dashboard and give access only to the date filter of the dashboard, not the city filter?

@beyondfire94 You are asking for Sandboxing, which is available in the Enterprise Edition:
https://www.metabase.com/learn/permissions/data-sandboxing-row-permissions

You can control filters manually if you use Embedding with Locked filter:
https://www.metabase.com/docs/latest/administration-guide/13-embedding.html

You can use Metabase API for that purpose.
There are several wrappers for Metabase API which make your job easier. E.g. this is a Python wrapper that I wrote (use the create_card function with custom_json parameter).

@flamber Thanks! I will try to work with the backend to integrate this feature!

@King_Edward Thanks, man! Is there any way to alternate the SQL code of these cards? I definitely will copy them with your wrapper but then I will have to change the city name in each of them. It will be much easier with your wrapper but still

You can create the cards with your desired SQL code.
It would be sth like:

q = '''
  select *
  from my_table 
  where city = '{}'
'''

for city in city_list:

  query = q.format(city)
  
  # use the query in your custom_json
  # here I included the minimum keys required. You can add more.
  my_custom_json = {
    'name': 'test_card',
    'display': 'table',
    'dataset_query': {
      'database': db_id,
      'native': { 'query': query },
      'type': 'native' 
    }
  }
       
  # create the card using the custom_json
  # See the function definition for other parameters of the function (e.g. in which collection to save the card)
  mb.create_card(custom_json=my_custom_json)

@King_Edward
Wow, it's really cool stuff you did! Thanks