Members-only tutorial
Watch the video and get the practice sheet with membership.
About this Tutorial
Sheet Resources
Video Transcript
<div>0:00 I am so glad you've made it to part two where Learn how to filter data with the query where clause in Google Sheets. Opens in new tab we learn how to write a function Understand what functions are and how to use them in Google Sheets. Opens in new tab . I went through it very quickly in the last video I showed you how to write a function Understand what functions are and how to use them in Google Sheets. Opens in new tab , but we're gonna step through it very slowly in this video.<br>0:11 So again, we're gonna go to our extensions app script Discover how to automate tasks in Google Sheets using Apps Script. Opens in new tab and find our function Understand what functions are and how to use them in Google Sheets. Opens in new tab once we're there. Let's write an actual function Understand what functions are and how to use them in Google Sheets. Opens in new tab we might want to use.<br>0:23 The last one we did was just math. So if we wanna add more functions Explore different types of functions available in Google Sheets. Opens in new tab , we can just go down and go fun.<br>0:29 Really write the num, the name function Understand what functions are and how to use them in Google Sheets. Opens in new tab , what what we're gonna do.
Common function Understand what functions are and how to use them in Google Sheets. Opens in new tab or math formula Get familiar with the syntax rules for writing functions in Google Sheets. Opens in new tab that we might want to create is something called cpm.<br>0:40 This is a bit of a little bit of math, very little bit. But what it is, let's see, we have a cost and we have some kind of a number Learn about number formatting and calculations in Google Sheets. Opens in new tab of impressions or views.<br>0:54 We use this across any sort Find out how to sort data effectively in Google Sheets. Opens in new tab of social media. We use it a lot. I've used a lot in the past cpm.<br>0:59 So we want our CPM here. Now, if we have a cost of like $566 of cross, you know, a million impressions, all we have to do is we can do this in formula Get familiar with the syntax rules for writing functions in Google Sheets. Opens in new tab , right?<br>1:13 We can say equals c4, nope, c3, the cost divided by C4 divided by 1000.
So we take the number Learn about number formatting and calculations in Google Sheets. Opens in new tab of impressions divided by a thousand and then take the cost and divide it by that, right?<br>1:28 And so our cost per is gonna be per thousand is gonna be 57 cents, but we don't want to have to show this math, but we also want to provide sort Find out how to sort data effectively in Google Sheets. Opens in new tab of a name we want to type in just really equals CPM and get that num and enter these two numbers and get that number Learn about number formatting and calculations in Google Sheets. Opens in new tab .<br>1:47 So let's do that. So we're gonna go function Understand what functions are and how to use them in Google Sheets. Opens in new tab cpm, we're gonna have cost comma views, let's say not just impressions.<br>1:56 We want to do curly brackets and then we're gonna do fun.
We're gonna do variable melay is cost per miele.<br>2:06 Actually we can write that out. Cost per millet. So our miele is gonna be equals count divided by 1000. We can end each line with a semicolon if we want that.<br>2:18 So something from JavaScript we can do. Variable CPM is equal to the cost divided by this variable up here, Miele, end it with a semi.<br>2:31 Now the number Learn about number formatting and calculations in Google Sheets. Opens in new tab we wanna return, we always wanna return something, return cpm, hit command S four safe. Now we can use this function Understand what functions are and how to use them in Google Sheets. Opens in new tab equals cost per me life.<br>2:44 C4, no c3, c4. And we get an error Understand common errors you might encounter in Google Sheets. Opens in new tab .
So it tells us in this error Understand common errors you might encounter in Google Sheets. Opens in new tab F reference Learn how to use cell references in your formulas and functions. Opens in new tab error Understand common errors you might encounter in Google Sheets. Opens in new tab count is not defined and tells us where Learn how to filter data with the query where clause in Google Sheets. Opens in new tab it is.<br>2:56 Line seven, line seven count. Ah, because we don't have a count, we have views. So we can just rename these views, command S, and we should get rid of that error Understand common errors you might encounter in Google Sheets. Opens in new tab .<br>3:08 We can probably just copy and paste this to get to try it again. And there we go. 57, we have completed it.<br>3:17 Great. So in this we just wrote, we just wrote variables. These are all variables.
Var then the name of the variable and we can name those variables, anything we want, but we just have to remain consistent to know to use them again and variables are editable.<br>3:36 So Google Script will show you, as I mentioned, the last video and this video, if we don't use Miele, if we used sort Find out how to sort data effectively in Google Sheets. Opens in new tab of mile, if we mistype that, see this Miele is a little bit sort Find out how to sort data effectively in Google Sheets. Opens in new tab of grayed out.<br>3:49 So it'll tell us, hey, we're not using this variable somewhere. So, oh, we got it right here and now it is using it.<br>3:55 Some errors you might run into.
So if we wrote the function Understand what functions are and how to use them in Google Sheets. Opens in new tab named cost per melay up here and we start typing equals cost per mile, let's say, and we do the same thing, C3 comma c4, we're gonna get an error Understand common errors you might encounter in Google Sheets. Opens in new tab hashtag name and it says unknown function Understand what functions are and how to use them in Google Sheets. Opens in new tab cost per mile.<br>4:18 So what you can do is you can go back to your functions Explore different types of functions available in Google Sheets. Opens in new tab and say where Learn how to filter data with the query where clause in Google Sheets. Opens in new tab ? Well here it is. Oh, I spelled it wrong.<br>4:25 You mean even com Command C Copy and try to paste it to see if that fixes it.
And that does you already saw reference Learn how to use cell references in your formulas and functions. Opens in new tab error Understand common errors you might encounter in Google Sheets. Opens in new tab , but I'm gonna redo Discover how to redo actions in Google Sheets to correct mistakes. Opens in new tab it again.<br>4:36 So if say this said mile here and we go back, it says error Understand common errors you might encounter in Google Sheets. Opens in new tab and it says reference Learn how to use cell references in your formulas and functions. Opens in new tab error Understand common errors you might encounter in Google Sheets. Opens in new tab . Melay is not defined Line eight.<br>4:49 So we go to our function Understand what functions are and how to use them in Google Sheets. Opens in new tab , we go to line eight and we say, Miele, where Learn how to filter data with the query where clause in Google Sheets. Opens in new tab ? Where is it? Oh, it's not defined here because mile is spell MI is spelled wrong as mile.<br>4:58 There we go. We've debugged that.
And then also see that you sort Find out how to sort data effectively in Google Sheets. Opens in new tab of get an error Understand common errors you might encounter in Google Sheets. Opens in new tab with just typing this name even though it does exist as a function Understand what functions are and how to use them in Google Sheets. Opens in new tab .<br>5:11 It tells us unknown function Understand what functions are and how to use them in Google Sheets. Opens in new tab until we hit enter costs per might have to redo Discover how to redo actions in Google Sheets to correct mistakes. Opens in new tab that because we did fix that error Understand common errors you might encounter in Google Sheets. Opens in new tab .<br>5:24 Unknown function Understand what functions are and how to use them in Google Sheets. Opens in new tab , hit enter and it still works. So this function Understand what functions are and how to use them in Google Sheets. Opens in new tab does exist, but in our sheet it doesn't tell us that it exists or it tell, it tells us that it does not exist.<br>5:38 There is actually an interesting way to fix this. If you want to check it out, go Google for custom function.<br>5:44 It adds a little bit of text.
I go deeper into this in advanced courses, but this course we wanna remain simple.<br>5:52 So thank you for watching. Watch.</div>
Courses
Why Code in Google Sheets? - Learn to Code in Google Sheets Part 1
Tips to Navigating Thousands of Lines of Code In Apps Script
How to Write a Function - Learn to Code in Google Sheets Part 2
From Sheet to Script And Back Again - Learn to Code In Google Sheets Part 3
Copy That, From One Sheet to Another - Learn to Code in Google Sheets Part 4
Now Do It Every Damn Day - Learn to Code in Google Sheets Part 5
Wrap Your Mind Around This - Learn to Code in Google Sheets Part 6
Write Your First Script
00:08:31
How to Record Macros
00:06:20
How to Edit a Macro
00:08:22
How to Trigger Macros Daily
00:06:58
Automatically Uncheck A Daily Checklist
How do I reference a different spreadsheet in Apps Script?