Skip to main content

Screen orientation calculation in Google Data Studio

Daniel Perry-Reed6 May 20222 min read
Screen orientation calculation in Google Data Studio

If you're just here for the screen orientation CASE formula to use in Google Data Studio, here it is:

CASE 
    WHEN CAST(REGEXP_REPLACE(Screen Resolution, 'x.*', '') AS NUMBER)<CAST(REGEXP_REPLACE(Screen Resolution, '.*x', '') AS NUMBER) THEN "Portrait"
    ELSE "Landscape"
END

Digging into it a bit further, the way tis works is that it takes the bit before the ‘x’ of the Screen Resolution dimension (the x-axis), and sees if it’s smaller than the bit after the ‘x’ (the y-axis). So if the x-axis is less than the y-axis the screen orientation is portrait, otherwise it’s landscape.

I’m using the Universal Analytics dimension 'Screen Resolution' in this example, but you can swap out that for any other reference you have, as long as it has the same format of ‘AxB’ - i.e. 900x800. You can even swap out the 'x' if there is another delimiter in your data. This screen orientation calculation is agnostic and easily changed to fit whatever your data looks like.

In Data Studio, you can add this in the data source itself, or as a custom calculation in any chart as such:

Data Studio interface with the calculation editor open with the formula for screen orientation visible

Using this newly created dimension, you can use them in charts to break down any data into landscape and portrait.

Data Studio bar and pie charts showing screen orientation (landscape and portrait) by day

It's also useful in tables where you can use it as a filter to give the viewer a different way to view device data. For example:

Data Studio table showing a filter control for screen orientation with both portrait and landscape selected
Data Studio table showing a filter control for screen orientation with portrait selected

A small improvement on the formula at the top of this post is below where it accounts for square resolutions too! Not that it occurs frequently to be honest, but it's all about being precise.

CASE 
    WHEN CAST(REGEXP_REPLACE(Screen Resolution, 'x.*', '') AS NUMBER)<CAST(REGEXP_REPLACE(Screen Resolution, '.*x', '') AS NUMBER) THEN "Portrait"
    WHEN CAST(REGEXP_REPLACE(Screen Resolution, 'x.*', '') AS NUMBER)>CAST(REGEXP_REPLACE(Screen Resolution, '.*x', '') AS NUMBER) THEN "Landscape"
    ELSE "Square"
END

They do exist though:

Data Studio table showing a filter control for screen orientation with 'square' selected

We cover this example and lots of others in our Data Studio Kickstarter training course. If you'd like to book in the training for your team, or have any questions about it, please get in touch.


Suggested content

Measurelab awarded Google Cloud Marketing Analytics Specialisation

At the start of the year, if you’d asked us whether Measurelab would be standing shoulder to shoulder with Europe’s biggest consultancies by September, we would've been surprised. Not because we don't believe in ourselves, but because these things feel so distant - until suddenly, they’re not. So, here it is: we’ve been awarded the Marketing Analytics Services Partner Specialisation in Google Cloud Partner Advantage. What’s the big deal? In Google’s own words (with the obligatory Zs): “Spec

Will Hayes11 Sept 2025

BigQuery AI.GENERATE tutorial: turn SQL queries into AI-powered insights

BigQuery just got a major upgrade, you can now plug directly into Vertex AI using the new AI.GENERATE function. Translation: your analytics data and generative AI are now best friends, and they’re hanging out right inside SQL. That opens up a whole world of new analysis options for GA4 data, but it also raises some questions: * How do you actually set it up? * What’s it good for (and when should you avoid it)? * Why would you batch the query? Let’s walk through it step by step. Step 1: H

Katie Kaczmarek3 Sept 2025

How to start forecasting in BigQuery with zero training

If you’d told me five years ago that I’d be forecasting product demand using a model trained on 100 billion time points… without writing a single line of ML code… I probably would’ve asked how many coffees you’d had that day ☕️ But its a brand new world. And it’s possible. Let me explain What is TimesFM? TimesFM is a new foundation model from Google, built specifically for time-series forecasting. Think of it like GPT for time, instead of predicting the next word in a sentence, it predicts t

Katie Kaczmarek14 Jul 2025