Hello!
I'm a beginner with Google Looker and need some assistance.
I'm trying to represent a pie chart from a table similar to this:
Month | Animals | Humans |
January | 1 | 4 |
February | 3 | |
January | 2 |
I would like to see in the same pie chart 2 portions with the percentage of the total sum of Animals and Humans according to the Month.
I have set up a control for the Month, and it works fine. For the Dimension of the pie chart, I have created a field with the following formula:
CASE
WHEN Animals IS NOT NULL THEN "Animals"
WHEN Humans IS NOT NULL THEN "Humans"
END
But for the Metric, I can't figure out how to calculate the total for each column "Animals" and "Humans." Using the "Record Count" metric only counts the rows, but that's not what I need.
Could you lend me a hand?
Solved! Go to Solution.
Hi,
The current data layout isn’t ideal for a pie chart from the data source, as each category (animal and human) is split across separate columns. To make it chart-ready, we must reshape the data by pivoting those columns into rows and adding a new “Category” field to label the entry. Looker Studio doesn’t support native data pivoting, so we’ll handle this transformation using Google Apps Script in Google Sheets. (Of course, you could achieve a similar result using other functions like QUERY, etc.) Once the data is restructured, it’ll be perfectly formatted for a pie chart in Looker Studio.
For reference and to see the expected output, click the link below.
https://lookerstudio.google.com/u/0/reporting/3783fcd6-233a-4032-8f30-d6fd37de327f/page/lGaGF
Original:
Transposed:
Why not put the date in the dimension, and have the Animal and Human fields in the metrics? Looker Studio will automatically sum the columns separately. Or did I misunderstand something?
Hi,
The current data layout isn’t ideal for a pie chart from the data source, as each category (animal and human) is split across separate columns. To make it chart-ready, we must reshape the data by pivoting those columns into rows and adding a new “Category” field to label the entry. Looker Studio doesn’t support native data pivoting, so we’ll handle this transformation using Google Apps Script in Google Sheets. (Of course, you could achieve a similar result using other functions like QUERY, etc.) Once the data is restructured, it’ll be perfectly formatted for a pie chart in Looker Studio.
For reference and to see the expected output, click the link below.
https://lookerstudio.google.com/u/0/reporting/3783fcd6-233a-4032-8f30-d6fd37de327f/page/lGaGF
Original:
Transposed:
Solved! Thank you for your help
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |