Button to Switch Between Functions? (Median and Average)

I have a bar chart that currently displays an average using the AVG function within looker studio. However, I'd love to have a way for the user to switch the function between AVG and MED function. Wondering if there is a simple control in looker studio that would allow this, or if I will have to handle this manually on the data side.

2 REPLIES 2

Hello, I think you can use the "optional metrics" functionality. Add the same metric to both fields and apply different calculation methods—one for median, and the other for average (see first reference below).

_3-1744165551080.png

 

 

When external users view your report, they just need to click the small icon to switch or add more metrics to the report (see reference below).

_2-1744165485914.png

 

_1-1744165467899.png

 

 

You could also set up a parameter with two values: Median and Average. Then set up a calculated field using CASE like this.

CASE
WHEN parameter_name="Median" then MEDIAN(Checkout Cost)
WHEN parameter_name="Average" then AVG(Checkout Cost)
END

Use the calculated field as the X-axis in your bar chart, and add a control for the parameter (fixed size works well for this.) You may also want to add a dynamic text box for the x-axis label to reflect the selected parameter.