How to create Custom Regions in Google Data Studio using CASE statements
The CASE statement in Google Data Studio allows users to create new categories and dimensions.
“CASE statements let you create new fields that use conditional logic to determine the field values. CASE is most often used to create new categories or groupings of data.” – Data Studio Help
For this example we will be creating custom geographical dimensions . We will use three Regional economic communities in Africa as an example.
Specifically we will be creating three new dimensions . These will be the Southern African Development Community (SADC), the Economic Community of West African States (ECOWAS), and the Arab Maghreb Union (AMU)
As this is just an example, we will not include all the regional trading blocs in Africa.
In Google Data Studio, click ‘Add a Field’ to create our new regional categories. We will be basing this CASE statement on the example below by Data Studio.
CASE
WHEN Country IN ("USA","Canada","Mexico")THEN "North America"
WHEN Country IN ("England","France")THEN "Europe"
ELSE "Other"
END
We will add our own countries and regional groupings to the code, as seen below.
Once this is done we have a new field named ‘Regional economic communities in Africa’.
CASE
WHEN Country IN
("Angola","Botswana","Comoros","Democratic Republic of Congo","Lesotho","Madagascar","Malawi","Mauritius","Mozambique","Namibia","Seychelles","South Africa","Swaziland","Tanzania","Zambia","Zimbabwe"
)THEN "SADC"
WHEN Country IN
("Algeria","Libya","Mauritania","Morocco","Tunisia"
)THEN "Arab Maghreb Union"
WHEN Country IN
("Cape Verde","Gambia","The Gambia", "Guinea","Guinea-Bissau","Liberia","Mali","Senegal","Sierra Leone","Benin","Burkina Faso","Ghana","Ivory Coast","Côte d’Ivoire","Niger","Nigeria","Togo"
)THEN "ECOWAS"
ELSE "Other"
END
Note that we can include different names for countries. For example, if we include “Ivory Coast” and “Côte d’Ivoire” we make sure we get that country’s data.
The Data Studio report below shows website visitors by country. We can use the top filter to choose which economic region we want to look at.