I am creating a Grafana dashboard with Microsoft SQL Server as the data source (fetching data via Synapse Serverless SQL from a Parquet data lake in Azure).
In this setup I have a list of column names stored in the variable signal
. There can be one or more column names. For the purpose of creating a dynamic dropdown, I need to create a Grafana drop down list that uses a Microsoft SQL Server query to transform my list of column names as per below:
If the signal values are roll
, pitch
, then the query should produce the below:
AVG(roll) AS AVG_roll , AVG(pitch) AS AVG_pitch , MIN(roll) AS MIN_roll , MIN(pitch) AS MIN_pitch , MAX(roll) AS MAX_roll , MAX(pitch) AS MAX_pitch
In an equivalent Grafana-Athena dashboard I manage to do this as follows:
SELECT
array_join(
concat(
transform(split('${signal:csv}', ','), x -> 'AVG(' || REPLACE(x, ' ', '') || ') AS AVG_' || x),
transform(split('${signal:csv}', ','), x -> 'MIN(' || REPLACE(x, ' ', '') || ') AS MIN_' || x),
transform(split('${signal:csv}', ','), x -> 'MAX(' || REPLACE(x, ' ', '') || ') AS MAX_' || x)
),
', '
);
However, I seem unable to figure out a way to achieve the same within the Microsoft SQL Server syntax. Note that the ${signal:csv}
could be replaced with e.g. ${signal:singlequote}
and others that may be easier to work with (as per Grafana’s documentation)