<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>regular expressions Archives | Data Studio</title>
	<atom:link href="https://www.datastudio.ca/tag/regular-expressions/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>AI and Analytics Tips, Techniques and Tutorials</description>
	<lastBuildDate>Tue, 20 Jul 2021 18:03:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>

<image>
	<url>https://www.datastudio.ca/wp-content/uploads/2020/01/cropped-Logo-80x80.png</url>
	<title>regular expressions Archives | Data Studio</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Top 5 Most Useful Calculated Fields and Functions in Google Data Studio</title>
		<link>https://www.datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio/</link>
					<comments>https://www.datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio/#comments</comments>
		
		<dc:creator><![CDATA[Lachezar Arabadzhiev]]></dc:creator>
		<pubDate>Wed, 04 Mar 2020 04:57:07 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[channel groupings]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[regular expressions]]></category>
		<guid isPermaLink="false">https://datastudio.ca/?p=1008</guid>

					<description><![CDATA[<p>Calculated fields and functions are at the core of Google Data Studio! In this post, I want to&#8230;</p>
<p>The post <a href="https://www.datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio/">Top 5 Most Useful Calculated Fields and Functions in Google Data Studio</a> appeared first on <a href="https://www.datastudio.ca">Data Studio</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Calculated fields and functions are at the core of Google Data Studio! In this post, I want to share with you a few practical use-cases that I find quite helpful and time-saving. As you probably already know, the Data Studio functions are always evolving, so I will try to keep this post up-to-date, if any changes occur in the future.</p>



<h2 id="summary" class="wp-block-heading">Summary</h2>



<ol class="wp-block-list"><li><strong><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#case">CASE Functions in Data Studio</a></strong><ol><li><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#custom">Scenario 1: How do I re-create my Google Analytics &#8220;Custom Channel Groupings&#8221; in Google Data Studio?</a></li></ol></li><li><strong><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#regexp">REGEXP_EXTRACT and REGEXP_REPLACE Functions in Data Studio</a></strong><ol><li><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#utm">Scenario 1: How to extract a UTM parameter into a separate dimension with REGEXP_EXTRACT?</a></li><li><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#replace">Scenario 2: How to remove parameters from URLs with REGEXP_REPLACE?</a></li></ol></li><li><strong><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#image">CONCAT and IMAGE Functions in Data Studio</a></strong><ol><li><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#concat">Scenario 1: How do I use CONCAT to combine dimensions?</a></li><li><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#display">Scenario 2: How do I use CONCAT with IMAGE to display images in a table?</a></li></ol></li><li><strong><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#datediff">DATE_DIFF Function</a></strong><ol><li><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#calc">Scenario 1: How do I calculate the difference between two dates using DATE_DIFF?</a></li></ol></li><li><strong><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#lower">LOWER/UPPER Function</a></strong><ol><li><a href="https://datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio#text">Scenario 1: How to use LOWER and UPPER functions to standardize text strings?</a></li></ol></li></ol>



<p>Let&#8217;s dive into the world of functions! <img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<h2 class="wp-block-heading" id="case"><span id="1-case-functions-in-data-studio">1. CASE Functions in Data Studio</span></h2>



<p>In a previous post, I wrote an introductory article with a lot of examples on <a href="https://datastudio.ca/functions/how-to-use-the-case-function-in-google-data-studio/">how to use CASE statements in Google Data Studio</a>, so if you are starting out, I would recommend you to look at that first. For this scenario, I want to focus on a more complex use of the CASE function. </p>



<h3 id="scenario-1-how-do-i-re-create-my-google-analytics-custom-channel-groupings-in-google-data-studio" class="wp-block-heading">Scenario 1: How do I re-create my Google Analytics &#8220;Custom Channel Groupings&#8221; in Google Data Studio?</h3>



<p>In Google Analytics, users have the capability to create &#8220;<a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://support.google.com/analytics/answer/6010097?hl=en" target="_blank">Custom Channel Groupings</a>&#8221; that allow them to sort how users have arrived at their website (eg. direct, organic search and etc). However, the Google Analytics native connector for Data Studio does not offer those groupings. Therefore, you have to create them yourself with a CASE, which is actually a positive, because Data Studio gives you much more flexibility with functions when compared to the &#8220;Custom Channel Groupings&#8221; in Google Analytics.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="986" height="544" src="https://www.datastudio.ca/wp-content/uploads/2020/03/b59dc12c-custom-channel-groupings.png" alt="google analytics custom channel groupings" class="wp-image-1046" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/b59dc12c-custom-channel-groupings.png 986w, https://www.datastudio.ca/wp-content/uploads/2020/03/b59dc12c-custom-channel-groupings-300x166.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/b59dc12c-custom-channel-groupings-768x424.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/b59dc12c-custom-channel-groupings-380x210.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/b59dc12c-custom-channel-groupings-800x441.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/b59dc12c-custom-channel-groupings-80x44.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/b59dc12c-custom-channel-groupings-760x419.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/b59dc12c-custom-channel-groupings-600x331.png 600w" sizes="(max-width: 986px) 100vw, 986px" /></figure>



<p>As usual, you would have to create a new calculated field at the data source-level. Since the &#8220;Custom Channel Groupings&#8221; are going to include an extensive list of &#8220;Source/Medium&#8221; attributes, your CASE might get a bit crowded. Nothing to worry about, I have already pre-written the code for you, but here are a few callouts:</p>



<ul class="wp-block-list"><li>All CASE statements follow a sequential order when executing. For example, if your rule for &#8220;Paid Search&#8221; is generic, that might pick up the &#8220;Organic Search&#8221; data before the specific rule for &#8220;Organic Search&#8221; has had the chance to run.</li><li>You can use OR and AND combinations within your CASE to make things more digestible. I highly recommend that.</li><li> Always have a back-up rule! For example, you might have &#8220;Social Source Referral=Yes&#8221;, but if Google Analytics misclassifies your social channel &#8211; &#8220;l.facebook&#8221;- as  &#8220;Referral&#8221;, you need to have that addressed with a regular expression.</li></ul>



<pre class="wp-block-code"><code>CASE 
WHEN (Source="(direct)" AND Medium="(none)") OR (Source="(direct)" AND Medium="(not set)") THEN "Direct"
WHEN (Source="google" AND Medium="cpc") OR REGEXP_MATCH(Medium,"(cpc|ppc)") THEN "Paid Search" 
WHEN Medium="organic" OR REGEXP_MATCH(Source, ".*(^google|baidu|bing).*|.*(search).*") THEN "Organic Search" 
WHEN Social Source Referral="Yes" OR REGEXP_MATCH(Source,".*(social|fb|facebook|twitter|linkedin|pinterest).*") THEN "Social" 
WHEN REGEXP_MATCH(Source, ".*(mail|outlook).*") THEN "E-mail" 
WHEN REGEXP_MATCH(Source, ".*(youtube).*") THEN "Video YouTube"
WHEN Medium="affiliate" THEN "Affiliates" 
WHEN (Source="dfa" AND Medium="cpm") OR REGEXP_MATCH(Source,"(display|banner|native|.*(doubleclick).*)") THEN "Display (Campaign Manager)"
WHEN Medium="referral" THEN "Referral" 
ELSE "(Other)" 
END</code></pre>



<h2 class="wp-block-heading" id="regexp"><span id="2-regexp_extract-and-regexp_replace-functions-in-data-studio">2. REGEXP_EXTRACT and REGEXP_REPLACE Functions in Data Studio</span></h2>



<h3 class="wp-block-heading" id="utm"><span id="scenario-1-how-to-extract-a-utm-parameter-into-a-separate-dimension-with-regexp_extract">Scenario 1: How to extract a UTM parameter into a separate dimension with REGEXP_EXTRACT?</span></h3>



<p>If you have multiple campaigns and want to see how each one is contributing to your business, the REGEXP_EXTRACT function can be a real time-saver. Here is an example, the URL below includes a campaign name that we want to extract, as that part of the UTM is valuable to us.</p>



<p><em>https://datastudio.ca/?utm_source=dfa&amp;utm_medium=cpm&amp;utm_<strong>campaign=summer_sale</strong></em></p>



<p>In this case, you would have to write the formula below. Firstly, selecting the dimensions that you want to extract from &#8211; &#8220;URL (with utm)&#8221;. After that, the regular expression simply says <em>&#8220;starting from <strong>campaign=</strong> match everything until you reach another <strong>&amp;</strong>&#8220;</em>.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="288" src="https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract-1024x288.png" alt="data studio functions regexp_extract syntax" class="wp-image-1033" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract-1024x288.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract-300x84.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract-768x216.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract-380x107.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract-800x225.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract-80x23.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract-760x214.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract-600x169.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/03/73b72093-regexp_extract.png 1037w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Once you apply the function, the result is pretty cool. We have extracted the campaign name in a separate and much cleaner dimension.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="373" src="https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-1024x373.png" alt="REGEXP_EXTRACT column with campaigns" class="wp-image-1039" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-1024x373.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-300x109.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-768x280.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-380x138.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-800x291.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-1160x423.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-80x29.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-760x277.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm-600x219.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/03/0b75c318-utm.png 1359w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading" id="replace"><span id="scenario-2-how-to-remove-parameters-from-urls-with-regexp_replace">Scenario 2: How to remove parameters from URLs with REGEXP_REPLACE?</span></h3>



<p>Building upon the previous function, let&#8217;s assume that you want to remove all parameters to get the original URL. This is often used when you want to only see the traffic to a landing page and ignore all parameters. In our case, you can write the formula below. Once again, the regular expression says <em>&#8220;look for anything after <strong>?</strong>&#8220;</em>. Then, the third argument specifies what we want our replacement to be. We simply leave that blank.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="911" height="334" src="https://www.datastudio.ca/wp-content/uploads/2020/03/8c7468d1-regexp_replace.png" alt="data studio functions regexp_replace formula syntax" class="wp-image-1035" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/8c7468d1-regexp_replace.png 911w, https://www.datastudio.ca/wp-content/uploads/2020/03/8c7468d1-regexp_replace-300x110.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/8c7468d1-regexp_replace-768x282.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/8c7468d1-regexp_replace-380x139.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/8c7468d1-regexp_replace-800x293.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/8c7468d1-regexp_replace-80x29.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/8c7468d1-regexp_replace-760x279.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/8c7468d1-regexp_replace-600x220.png 600w" sizes="auto, (max-width: 911px) 100vw, 911px" /></figure>



<p>The final table would look something like this and our URL is now much more visible. </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="376" src="https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-1024x376.png" alt="REGEXP_REPLACE column with url" class="wp-image-1038" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-1024x376.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-300x110.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-768x282.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-380x140.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-800x294.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-1160x426.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-80x29.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-760x279.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table-600x221.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/03/c254612e-regexp_replace_table.png 1496w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="image"><span id="3-concat-and-image-functions-in-data-studio">3. CONCAT and IMAGE Functions in Data Studio</span></h2>



<h3 class="wp-block-heading" id="contact"><span id="scenario-1-how-do-i-use-concat-to-combine-dimensions">Scenario 1: How do I use CONCAT to combine dimensions?</span></h3>



<p>This is a function that could prove to be extremely useful, especially if you are working with <a href="https://www.google.com/dfa/trafficking">Campaign Manager (CM)</a> or <a href="https://ads.google.com/intl/en_ca/home/">Google Ads</a>. For many organizations, <em>&#8220;naming conventions&#8221;</em> are important, as they allow for easy data parsing.  Well, with the CONCAT function, you can combine a few pre-existing fields into a single and more powerful dimension. Here is how it works:</p>



<p>Luckily, the function has a simple syntax. You type your first dimension, in this case, &#8220;Campaign Name&#8221; and then a delimiter. The delimiter specifies how dimensions will be separated from each other. A few common delimiters are &#8220;|&#8221;(pipe) and &#8220;,&#8221;(comma).</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="943" height="89" src="https://www.datastudio.ca/wp-content/uploads/2020/03/9456ca8b-concat-syntax.png" alt="data studio functions concat syntax" class="wp-image-1017" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/9456ca8b-concat-syntax.png 943w, https://www.datastudio.ca/wp-content/uploads/2020/03/9456ca8b-concat-syntax-300x28.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/9456ca8b-concat-syntax-768x72.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/9456ca8b-concat-syntax-380x36.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/9456ca8b-concat-syntax-800x76.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/9456ca8b-concat-syntax-80x8.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/9456ca8b-concat-syntax-760x72.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/9456ca8b-concat-syntax-600x57.png 600w" sizes="auto, (max-width: 943px) 100vw, 943px" /></figure>



<p>The result is a compact and more informative dimension that combines all of the three fields. Remember, you can add as many dimensions as you want, as long as the final field is useful to you.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="202" src="https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat-1024x202.png" alt="concat function result highlighted in red" class="wp-image-1012" srcset="https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat-1024x202.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat-300x59.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat-768x151.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat-380x75.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat-800x158.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat-80x16.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat-760x150.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat-600x118.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/02/0454ac7a-concat.png 1092w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading" id="display"><span id="scenario-2-how-do-i-use-concat-with-image-to-display-images-in-a-table">Scenario 2: How do I use CONCAT with IMAGE to display images in a table?</span></h3>



<p>A more advanced and exciting use of the CONCAT function is nesting it inside an IMAGE function.  For this scenario, I have used the product data from the <a rel="noreferrer noopener" aria-label="Google Analytics Demo Account (opens in a new tab)" href="https://analytics.google.com/analytics/web/demoAccount" target="_blank">Google Analytics Demo Account</a>. All we are doing here is, using &#8220;Product SKU&#8221; as a dynamic dimension since the product code is used in the URL. You can apply this same methodology with your eCommerece data set, as long as you have a dynamic element in the URL.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="92" src="https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-1024x92.png" alt="IMAGE data studio functions syntax with CONCAT inside" class="wp-image-1041" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-1024x92.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-300x27.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-768x69.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-380x34.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-800x72.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-1160x104.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-80x7.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-760x68.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula-600x54.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/03/ca532a63-image-formula.png 1244w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Once you have created the IMAGE calculated field, you can add it to a table. You will see the images showing-up immediately. A little caveat, the IMAGE dimension is only supported in tables, not other chart types.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="365" src="https://datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-1024x365.jpg" alt="table with images column" class="wp-image-1040" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-1024x365.jpg 1024w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-300x107.jpg 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-768x274.jpg 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-1536x548.jpg 1536w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-380x136.jpg 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-800x285.jpg 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-1160x414.jpg 1160w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-80x29.jpg 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-760x271.jpg 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-1600x571.jpg 1600w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image-600x214.jpg 600w, https://www.datastudio.ca/wp-content/uploads/2020/03/6129dc80-image.jpg 1778w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="datediff"><span id="4-date_diff-function">4. DATE_DIFF Function</span></h2>



<h3 class="wp-block-heading" id="calc"><span id="scenario-1-how-do-i-calculate-the-difference-between-two-dates-using-date_diff">Scenario 1: How do I calculate the difference between two dates using DATE_DIFF?</span></h3>



<p>This is a familiar one for those of you who use SQL on a regular basis. The function returns the difference between two date/time values in a numeric format. An interesting scenario where I found this function useful is paid media for eCommerce. We often look at the time a user was exposed to an ad and the time he/she actually made a purchase. This gives us a sense of what we would call &#8220;time-lag&#8221;, which indicates that the user needs some time to think before committing to a purchase. This is exactly where DATE_DIFF kicks-in.  </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="221" src="https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-1024x221.png" alt="table with the DATE_DIFF function and date columns" class="wp-image-1020" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-1024x221.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-300x65.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-768x166.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-1536x332.png 1536w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-380x82.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-800x173.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-1160x251.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-80x17.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-760x164.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-1600x346.png 1600w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff-600x130.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/03/e91b4fa4-date_diff.png 1666w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>The formula is straight-forward, you just have to include the two date fields that need to be subtracted.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="290" src="https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula-1024x290.png" alt="data studio functions date_diff syntax" class="wp-image-1049" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula-1024x290.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula-300x85.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula-768x217.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula-380x108.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula-800x226.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula-80x23.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula-760x215.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula-600x170.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/03/232e2274-date_diff_formula.png 1039w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="lower"><span id="5-lower-upper-function">5. LOWER/UPPER Function</span></h2>



<h3 class="wp-block-heading" id="text"><span id="scenario-1-how-to-use-lower-and-upper-functions-to-standardize-text-strings">Scenario 1: How to use LOWER and UPPER functions to standardize text strings?</span></h3>



<p>Last but not least, this function allows you to standardize your text dimensions. For example, imagine you have an online form on your website with a free-form input field that asks <em>&#8220;How did you hear about us?&#8221;</em> and the input field is free-form. The user might input any type of capitalization, so to clean up the mess, we can use LOWER.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="387" src="https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-1024x387.png" alt="table with answers column and LOWER function" class="wp-image-1028" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-1024x387.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-300x113.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-768x290.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-380x144.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-800x302.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-1160x438.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-80x30.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-760x287.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower-600x227.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/03/e5e651fc-lower.png 1336w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>You can also use the UPPER function in a similar fashion, converting all provinces to the standard uppercase abbreviations.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="314" src="https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-1024x314.png" alt="table with provinces column and UPPER function" class="wp-image-1029" srcset="https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-1024x314.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-300x92.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-768x235.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-380x116.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-800x245.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-1160x355.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-80x24.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-760x233.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper-600x184.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/03/22491aff-upper.png 1215w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>I hope this was helpful and you can now use all of these Data Studio functions in your own projects! If you have any questions, feel free to DM me on&nbsp;<a href="https://www.linkedin.com/in/larabadzhiev/">LinkedIn</a>&nbsp;? </p>



<hr class="wp-block-separator has-text-color has-background has-black-background-color has-black-color is-style-wide"/>



<h2 id="dynamic-dashboards-and-data-analysis-with-google-data-studio-2021" class="wp-block-heading">Dynamic Dashboards and Data Analysis with Google Data Studio &#8211; 2021</h2>



<p>If you want to learn how to build powerful data visualizations and unlock insights that can help you drive business results for your clients or employers, take a look at my <a href="https://www.udemy.com/course/dynamic-dashboards-and-data-analysis-with-google-data-studio/?referralCode=ED2EC987F6AD37C6DED8">full course on Udemy.</a> </p>



<figure class="wp-block-image size-large"><a href="https://www.udemy.com/course/dynamic-dashboards-and-data-analysis-with-google-data-studio/?referralCode=ED2EC987F6AD37C6DED8" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://datastudio.ca/wp-content/uploads/2019/11/Video-Outro-Thumbnail_Updated.jpg-1024x576-1.jpg" alt="Google Data Studio Course" class="wp-image-710"/></a></figure>
<p>The post <a href="https://www.datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio/">Top 5 Most Useful Calculated Fields and Functions in Google Data Studio</a> appeared first on <a href="https://www.datastudio.ca">Data Studio</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.datastudio.ca/functions/top-5-most-useful-calculated-fields-and-functions-in-google-data-studio/feed/</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
			</item>
		<item>
		<title>How to use CASE statements in Google Data Studio? &#8211; 2021</title>
		<link>https://www.datastudio.ca/functions/how-to-use-the-case-function-in-google-data-studio/</link>
					<comments>https://www.datastudio.ca/functions/how-to-use-the-case-function-in-google-data-studio/#comments</comments>
		
		<dc:creator><![CDATA[Lachezar Arabadzhiev]]></dc:creator>
		<pubDate>Sun, 12 Jan 2020 04:09:09 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[CASE statements]]></category>
		<category><![CDATA[conditional expressions]]></category>
		<category><![CDATA[data studio tutorial]]></category>
		<category><![CDATA[regular expressions]]></category>
		<guid isPermaLink="false">https://datastudio.ca/?p=746</guid>

					<description><![CDATA[<p>In this post, we are going to explore one of the most useful functions in Google Data Studio,&#8230;</p>
<p>The post <a href="https://www.datastudio.ca/functions/how-to-use-the-case-function-in-google-data-studio/">How to use CASE statements in Google Data Studio? &#8211; 2021</a> appeared first on <a href="https://www.datastudio.ca">Data Studio</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this post, we are going to explore one of the most useful functions in Google Data Studio, the CASE. I personally think that knowing how to write a CASE is not only helpful in Data Studio, but also it allows you to understand how computer logic works. In addition, I have added a section on how to compose the new Simplified CASE statements.</p>



<p><strong>*NEW</strong> &#8211; By popular demand, I have decided to expand the comprehensive guide on CASE and added IF statements, as the Google Data Studio team has had some incredible updates over the past year. Enjoy!</p>



<h2 id="what-is-the-data-studio-case-function" class="wp-block-heading">What is the Data Studio CASE function?</h2>



<p>The CASE function returns dimensions and metrics based on conditional expressions; it is often used to create new groupings of data and sort them in categories. Let&#8217;s imagine the following scenario. In the table below, you have a paid digital marketing campaign that includes &#8220;EN&#8221; and &#8220;FR&#8221; in the campaign name. However, you want to see the table below only per &#8220;Language&#8221;. This is where you can use the CASE function to write a specific statement. </p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://datastudio.ca/wp-content/uploads/2020/01/CASE-Function-1-1024x207.png" alt="google data studio campaign data table with a column highlighted" class="wp-image-779"/></figure>



<p>The trick with the CASE function is that you often have to find a unique common denominator to parse the data correctly. In the statement below, I am opening the CASE with a WHEN, specifying the first condition. Then adding IN, which instructs Data Studio that I will be listing text strings. Finally, I go ahead and choose my campaign name(s) and specify with THEN what I want to name the result of my WHEN condition. I know&#8230;. this is a bit of a tongue twister.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="215" src="https://datastudio.ca/wp-content/uploads/2020/01/Language-1024x215.png" alt="google data studio case statement using in" class="wp-image-780" srcset="https://www.datastudio.ca/wp-content/uploads/2020/01/Language-1024x215.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-300x63.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-768x161.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-380x80.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-800x168.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-1160x244.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-80x17.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-760x160.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-600x126.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language.png 1286w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>The result is exactly what we were looking for. Now if we want to see the campaign simply filtered by the &#8220;Language&#8221; dimension, we can even exclude &#8220;Campaign&#8221;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="206" src="https://datastudio.ca/wp-content/uploads/2020/01/CASE-Done-1024x206.png" alt="table with language column highlighted" class="wp-image-781" srcset="https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-1024x206.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-300x60.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-768x154.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-1536x309.png 1536w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-380x76.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-800x161.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-1160x233.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-80x16.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-760x153.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-1600x322.png 1600w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done-600x121.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/01/CASE-Done.png 1781w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 id="how-to-use-regexp_match-function-within-case" class="wp-block-heading">How to use REGEXP_MATCH function within CASE?</h2>



<p>Now, what happens if things get more complicated. For example, in the &#8220;Complex Campaign&#8221; dimension, we have a lot of different and unique campaign iterations. If we were to use IN, then the list in the CASE function is going to grow substantially and we are more likely to make a mistake while writing it. This is why we are going to try out the REGEXP_MATCH function, also referred to as regex.</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://datastudio.ca/wp-content/uploads/2020/01/CASE-Advanced-1-1024x314.png" alt="table with campaign data" class="wp-image-783"/></figure>



<p><strong>Quick background:</strong> Regular expressions are a notation for describing sets of character in a specific word or any text string. Google Data Studio (and most Google products) uses the <a href="https://github.com/google/re2/wiki/Syntax">RE2-style syntax</a>.</p>



<p>We start the WHEN statement the same way, without much difference. However, the modified dimension i.e. &#8220;Campaign&#8221; is inside brackets, unlike IN where it is outside. All we are doing with the regular expression is telling Data Studio that every time the capital letters &#8220;EN&#8221; or &#8220;FR&#8221; are spotted in the &#8220;Complex Campaign&#8221; dimension, the text strings should be named &#8220;English&#8221; and &#8220;French&#8221;, respectively. In a little bit more detail:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="215" src="https://datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-1024x215.png" alt="google data studio case statement using regex match" class="wp-image-785" srcset="https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-1024x215.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-300x63.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-768x161.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-380x80.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-800x168.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-1160x244.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-80x17.png 80w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-760x160.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced-600x126.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/01/Language-Advanced.png 1286w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 id="how-to-write-simplified-case-statements-by-declaring-a-field-to-test-once" class="wp-block-heading"><strong>How to write simplified CASE statements by declaring a field to test once?</strong></h2>



<p>In recent feature updates, Google has made it even easier to write repetitive CASE statements by declaring the field at the beginning. For example, if you have the same &#8220;Campaign&#8221; name, but this time, you want to use the year as a matching criteria.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="252" src="https://datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-1024x252.png" alt="" class="wp-image-1593" srcset="https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-1024x252.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-300x74.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-768x189.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-1536x378.png 1536w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-2048x504.png 2048w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-380x93.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-800x197.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-1160x285.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-760x187.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-1600x394.png 1600w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-2320x571.png 2320w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1-600x148.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/11/Campaign-dimension-pivot-table-1.png 2350w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Following the same logic as our past examples, you would normally write this standard CASE statement.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="223" src="https://datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-1024x223.png" alt="standard case statement with campaign dimension" class="wp-image-1588" srcset="https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-1024x223.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-300x65.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-768x167.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-1536x334.png 1536w, https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-380x83.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-800x174.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-1160x252.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-760x165.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement-600x130.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/11/regular-case-statement.png 1583w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>However, with the simplified CASE statement, you can do the following and save a bit of time!</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="224" src="https://datastudio.ca/wp-content/uploads/2020/11/case-simplifed-1024x224.png" alt="simplified case statement with a campaign dimension " class="wp-image-1587" srcset="https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed-1024x224.png 1024w, https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed-300x66.png 300w, https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed-768x168.png 768w, https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed-1536x336.png 1536w, https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed-380x83.png 380w, https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed-800x175.png 800w, https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed-1160x254.png 1160w, https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed-760x166.png 760w, https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed-600x131.png 600w, https://www.datastudio.ca/wp-content/uploads/2020/11/case-simplifed.jpg 1583w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 id="how-to-create-if-statements-in-google-data-studio" class="wp-block-heading"><strong>How to create IF statements in Google Data Studio</strong>?</h2>



<p>This has been a highly anticipated function and everyone was ecstatic when Google brought it to life. Similar to other platforms, you can use the IF function to return a dimension based on a given condition or rule. The basic syntax is as follow:</p>



<h3 id="ifcondition-true_result-false_result" class="wp-block-heading"><strong>IF(condition, true_result, false_result)</strong></h3>



<h4 id="parameters" class="wp-block-heading"><strong>Parameters</strong></h4>



<ul class="wp-block-list"><li><strong>Condition</strong>. This is the expression to evaluate. It consists of any valid boolean expression.</li><li><strong>True_result:</strong> This refers to the value that will be returned if the condition is true. It can be any valid expression.</li><li><strong>False_result: </strong>This refers to the value that will be returned if the condition is false. It can be any valid expression</li></ul>



<p>Let&#8217;s look at an example. This simple condition will calculate if &#8220;Actual Sales&#8221; exceed the &#8220;Forecast Sales&#8221;. If they do, your new column will the &#8220;Bonus&#8221; by 1.4, which presumably is going to info you sales team. Then, bonuses will be distributed accordingly.</p>



<pre class="wp-block-code"><code>IF(Actual Sales > Forecast Sales, Bonus * 1.4, Bonus)</code></pre>



<p>In addition, you can use a more complex condition with regular expression matching and logical AND. Although AND and OR allow you to test multiple conditions, simple CASE and CASE are the best to use if there are more than two possible results. Let&#8217;s see how that works.</p>



<pre class="wp-block-code"><code>IF (Event name = "purchase" AND (REGEXP_MATCH(Page path, ".*clothes.*") OR REGEXP_MATCH(Page path, ".*hoodies.*")), "hoodies Sales", Page title)</code></pre>



<p>As you can see, the IF statement can be quite powerful. </p>



<h2 id="data-studio-case-examples-from-the-media-agency-world" class="wp-block-heading">Data Studio CASE examples from the Media Agency world:</h2>



<p>These are few of the most common CASE statements across the Google Marketing Platform (GMP), ready to be copy/pasted!</p>



<h3 id="google-campaign-manager-cm-language" class="wp-block-heading">Google Campaign Manager (CM) &#8211; Language</h3>



<pre class="wp-block-code"><code>CASE
WHEN REGEXP_MATCH(Campaign, '.*(EN).*') THEN 'English'
WHEN REGEXP_MATCH(Campaign, '.*(FR).*') THEN 'French'
ELSE 'Other Language'
END</code></pre>



<h3 id="display-and-video-360-dv360-language" class="wp-block-heading">Display and Video 360 (DV360) &#8211; Language</h3>



<pre class="wp-block-code"><code>CASE
WHEN REGEXP_MATCH(Insertion Order, '.*(EN).*') THEN 'English'
WHEN REGEXP_MATCH(Insertion Order, '.*(FR).*') THEN 'French'
ELSE 'Other Language'
END</code></pre>



<h3 id="display-and-video-360-dv360-standard-media-tactics" class="wp-block-heading">Display and Video 360 (DV360) &#8211; Standard Media Tactics</h3>



<pre class="wp-block-code"><code>CASE
WHEN REGEXP_MATCH(Line Item, '.*(Remarketing).*') THEN 'Remarketing'
WHEN REGEXP_MATCH(Line Item, '.*(Lookalikes).*') THEN 'Lookalikes'
WHEN REGEXP_MATCH(Line Item, '.*(Prospecting).*') THEN 'Prospecting'
ELSE 'Other Tactic'
END</code></pre>



<h3 id="google-ads-device-type" class="wp-block-heading">Google Ads &#8211; Device Type</h3>



<pre class="wp-block-code"><code>CASE
WHEN REGEXP_MATCH(Campaign, '.*((M|m)obile).*') THEN 'Mobile'
WHEN REGEXP_MATCH(Campaign, '.*((T|t)ablet).*') THEN 'Tablet'
WHEN REGEXP_MATCH(Campaign, '.*((C|c)omputer).*') THEN 'Desktop'
ELSE 'Other'
END</code></pre>



<h3 class="wp-block-heading" id="age-case"><span id="google-ads-age-breakdown-this-cleans-up-your-default-age-dimension">Google Ads &#8211; Age Breakdown (this cleans up your default age dimension)</span></h3>



<pre class="wp-block-code"><code>CASE
WHEN Age IN ('Undetermined') THEN 'Unknown'
WHEN Age IN ('18to24') THEN 'A18-24'
WHEN Age IN ('25to34') THEN 'A25-34'
WHEN Age IN ('35to44') THEN 'A35-44'
WHEN Age IN ('45to54') THEN 'A45-54'
WHEN Age IN ('55to64') THEN 'A55-64'
WHEN Age IN ('gt64') THEN 'A65+'
ELSE 'N/A'
END</code></pre>



<h3 id="ga360-or-google-analytics-free-blog-page-sorting" class="wp-block-heading">GA360 or Google Analytics (Free) &#8211; Blog &#8220;Page&#8221; Sorting</h3>



<pre class="wp-block-code"><code>CASE
WHEN REGEXP_MATCH(Page, ‘((?i).*.*/about.*).*’) THEN ‘About Us
WHEN REGEXP_MATCH(Page, ‘((?i).*.*/blog/.*).*’) THEN ‘Blog Posts’’
WHEN REGEXP_MATCH(Page, ‘((?i).*.*/contact$).*’) THEN ‘Contact Us’
WHEN REGEXP_MATCH(Page, ‘((?i).*^/blog$).*’) THEN ‘Blog Page’
WHEN REGEXP_MATCH(Page, ‘((?i).*^/solutions/.*).*’) THEN ‘Solutions Pages’
WHEN REGEXP_MATCH(Page, ‘((?i).*^/services$).*’) THEN ‘Services’
WHEN REGEXP_MATCH(Page, ‘((?i).*.*/blog/category/.*).*’) THEN ‘Blog Category Page’
WHEN REGEXP_MATCH(Page, ‘((?i).*^/products/.*).*’) THEN ‘Product Pages’
WHEN REGEXP_MATCH(Page, ‘((?i).*^/contact/.*).*’) THEN ‘Thank You – Contact’
CASE WHEN REGEXP_MATCH(Page, ‘((?i).*^/$|^/\\?.*).*’) THEN ‘Homepage’
ELSE ‘_Other’
END
</code></pre>



<p>I hope this was helpful! If you have any questions, feel free to DM me on <a href="https://www.linkedin.com/in/larabadzhiev/">LinkedIn</a> or <a href="https://datastudio.ca/#colophon">subscribe to my newsletter</a> for more updates <img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" />  </p>



<hr class="wp-block-separator is-style-wide"/>



<h2 class="wp-block-heading" id="dynamic-dashboards-and-data-analysis-with-google-data-studio">Dynamic Dashboards and Data Analysis with Google Data Studio</h2>



<p>If you want to learn how to build powerful data visualizations and unlock insights that can help you drive business results for your clients or employers, take a look at my&nbsp;<a href="https://www.udemy.com/course/dynamic-dashboards-and-data-analysis-with-google-data-studio/?referralCode=ED2EC987F6AD37C6DED8">full course on Udemy.</a></p>



<figure class="wp-block-image size-large"><a href="https://www.udemy.com/course/dynamic-dashboards-and-data-analysis-with-google-data-studio/?referralCode=ED2EC987F6AD37C6DED8" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://datastudio.ca/wp-content/uploads/2019/11/Video-Outro-Thumbnail_Updated.jpg-1024x576-1.jpg" alt="Google Data Studio Course" class="wp-image-710"/></a></figure>
<p>The post <a href="https://www.datastudio.ca/functions/how-to-use-the-case-function-in-google-data-studio/">How to use CASE statements in Google Data Studio? &#8211; 2021</a> appeared first on <a href="https://www.datastudio.ca">Data Studio</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.datastudio.ca/functions/how-to-use-the-case-function-in-google-data-studio/feed/</wfw:commentRss>
			<slash:comments>23</slash:comments>
		
		
			</item>
	</channel>
</rss>
