Preselected value of variable from database

Hi!
I’m creating a dashboard with postgres as data source. I’m populating a variable drop-down of week numbers from the database at the top of the dashboard.
I want the preselected value to be the highest value when you enter the dash, but It’s always the lowest. Doesn’t matter if i sort it in my variable query:
select distinct extract(week from time) as week from submits order by 1 desc
or by the sort query option.
I can see that the numbers appear in the correct order in the drop down when I change this, but still, the pre-selected is always the lowest.
Is there a way to change this?

My guess, that you have saved that lowest value as default value. Select the highest value and save it as default value

Great, thank you. I missed the save current variables check. This works as a workaround for me.
Although I would prefer to be able to set the first value of my selected order so I don’t have to manually do this step for every new week.
Is this possible?

Yes, you need to remove that “saved value”, but you can’t do that in the UI. You need to edit dashboard json model manually and remove current configuration for that env variable and save it. In this case dashboard variable won’t have saved (current) values, so first value from the query result will be always preselected (so make correct sort also with Grafana variable sort configuration, not just with SQL sort).

1 Like

Yes, perfect!
Thank you!