Is it possible to use dynamic labels in Google Sheets Query function?

I’m working on a Google Sheets project and I’m stuck with the QUERY function. I know we can set static labels like this:

QUERY(data, "SELECT Col1, Col2 LABEL Col2 'Total'")

But what if I want the label to change based on a cell value? For example, if A1 has ‘Grand Total’, can I make the label update automatically?

I’m trying to create a flexible report where users can choose different options from a dropdown. It would be great if the labels could change to match their selections.

Has anyone figured out a way to do this? Or am I missing something obvious? Any help would be appreciated!

I’ve faced a similar challenge when trying to create flexible reports in Google Sheets. The QUERY function itself doesn’t have a built‐in way to update labels dynamically based on a cell value. One workaround is to run the QUERY normally without setting the label and then apply a separate function to append the dynamic label. For instance, you could use an ARRAYFORMULA in another part of your sheet that references the cell with the dynamic text, and then combine the result with your query output. This two-step process might not be as sleek as a single QUERY, but it provides the flexibility needed for responsive reports.

hey, u could try using concatenation to build ur query string dynamically. like this:

=QUERY(data, "SELECT Col1, Col2 LABEL Col2 ‘"&A1&"’")

this way the label will change based on whats in A1. hope that helps!