Search code examples
looker-studio

Google data studio pie chart add custom legend text or label


Hey I am really new to google data studio and for this project I successfully added pie chart with contains gender details. As I am using CUSTOMER table which adds gender_id while they fill out the form. Customer tables looks like

Name   Email             DOB          gender_id
David  [email protected]   08/08/1990     1
Shyam  [email protected] 09/01/1985     2
Krita  [email protected] 01/01/2000     3
Suja   [email protected]    02/03/1995     2

I used the customer table to count total gender and pie chart displays legend or label as 1,2,3 and 4. Is there a way to change 1, 2, 3 and 4 into male, female, non-binary and dont want to say.

Pie chart looks as

Pie chart Image


Solution

  • for that you will have to add a new field to your database. The new field must convert the numbers to the respective texts, using the formula:

    CASE 
       WHEN  gender_id=1 THEN "male"
       WHEN  gender_id=2 THEN "female"
       WHEN  gender_id=3 THEN "non-binary"
       WHEN  gender_id=4 THEN "dont want to say"
    END
    

    Thus, you will have a new column explaining each genre. Instead of using the column with the numbers, use the new field created as dimension of the pie chart.