Each model is run independently, there is no shared context between them. This also means that it’s not possible to have a shared variable based on a code calculation. It’s also worth noting that variables can only be declared in dbt_project.yml and have to be set project-wide for a dbt invocation.
How complex is the thing you’re hitting the database for? One workaround for a complex calculation is to write the result to a separate table so you only need to evaluate it once.