Using conditional logic in data link URL

(Using JSON API datasource)

I have a grafana dashboard with a table and two dashboard variables, var1 and var2.
var1 is custom defined by a user selection (3 possible predetermined values) and var2 by a query.

I want to set up a data link with a URL to be used when clicking on a value of the column number.

The URL should look like the following by default:
https://test.com/${var1}/${__data.fields["number"]}

However, I want this URL to change only if var1 is equal to its third possible value, let’s call it x to simplify.

Here are the conditions if var1 is equal to x :
After the value of var1 in the URL, append the following : /name/${var2}/ followed by the rest of the URL.

So when var1 is equal to x the URL will look something like this :
https://test.com/x/name/(value of var2)/(value of data field number)

So how could I achieve something like this? Is there a way to use conditional statements in Grafana for variables, and if not, a workaround for it?

Thanks in advance :slightly_smiling_face:

Hi @ceid1987,

Welcome to the :grafana: community support forums !!

We are excited that you joined our OSS community. Please read about some of the FAQs in the community :slight_smile:

You cannot define write or define a condition (e.g. IF - ELSE) in the datalink.

However, what you can do is add a new field to the data in the JSON API using JSONata/JSONpath and then use that field value as a datalink.

But it requires expertise in JSONata/JSONpath which unfortunately I do not have :slight_smile:

So yes it is possible but will require some learning and testing.