Members-only tutorial

Watch the video and get the practice sheet with membership.

See membership options

Write Apps Script to Create a New Google Sheets Formula

About this Tutorial

Create a brand new custom formula in Apps Script. We'll do this for our Add-on we'll be publishing to the Google Workspace Marketplace.

Video Transcript

<div>0:00 Alright, before we write some Apps Script Learn about Google Apps Script and how it enhances your Sheets experience. Opens in new tab , that is our actual function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab in the add-on Discover how add-ons can extend the functionality of Google Sheets. Opens in new tab that we're gonna create. We're gonna name it, I'm gonna call it CPM custom function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab .<br>0:10 This is the thing we're gonna create, CPM, cost per mille. I don't need to do anything in the sheet itself.<br>0:16 All I have to do is go to extensions, Apps Script Learn about Google Apps Script and how it enhances your Sheets experience. Opens in new tab , and open up. Apps Script Learn about Google Apps Script and how it enhances your Sheets experience. Opens in new tab , and I can start.

It already has, if you've never worked in Apps Script Learn about Google Apps Script and how it enhances your Sheets experience. Opens in new tab before, it has function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab , my function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab , my function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab with a couple parentheses, and a couple curly brackets.<br>0:31 We're gonna rename this function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab to CPM. And then we're gonna need let me explain CPM. CPM is cost per mille.<br>0:40 It's a term used in advertising or, I mean, yeah, advertising and marketing. To take a cost, the amount of cost it takes to buy an ad, and the amount of views it gets, we're gonna divide that by a thousand, and say, what is the cost per thousand views or units.<br>1:01 Mille is one thousand in French.

So what we need is two inputs. We need cost, and then, comma, we're gonna add cost per of views.<br>1:11 We'll just save views, or units we can actually say here. It does not really matter, except to your user. Your user's gonna see, your very we want to say variable.<br>1:25 Actually, maybe that's const CPM equals, and it's usually, we'll take the units, divide by one thousand, and then we'll take the cost, and we'll divide it by that.<br>1:38 That is the entire. CPM function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab , and we need to return something in this return, in this add-on Discover how add-ons can extend the functionality of Google Sheets. Opens in new tab , turn CPM.

That is the entire thing.<br>1:52 We can actually test it now that it is a function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab that is written. We have saved it. I hit save up here, or command S, we can call this CPM.<br>2:01 Pm. Custom. Function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab . If we want. We can use it. We can see. Okay, here's our cost. Here's our views. And we can say our cost is 500, and our views are 500,000.<br>2:17 So if we did the math here cost 500 divided by. The views divided by 1000 would be one. That is what we should get.<br>2:27 All of that math should be CPM. D4, comma. Yeah, D4, D5. Let's see if this comes out with. One.

Perfect.<br>2:43 So our CPM function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab is absolutely working correctly. If we had some text, I think it will get some error Explore common errors in Google Sheets and how to troubleshoot them. Opens in new tab . Yeah, in our actual function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab here that we did.<br>2:54 Oh, be very safe. D4. We had a value error Explore common errors in Google Sheets and how to troubleshoot them. Opens in new tab and we have a number Get insights into number formatting and calculations in Google Sheets. Opens in new tab error Explore common errors in Google Sheets and how to troubleshoot them. Opens in new tab result was not a number Get insights into number formatting and calculations in Google Sheets. Opens in new tab .<br>3:01 So we are still getting. Error Explore common errors in Google Sheets and how to troubleshoot them. Opens in new tab even if we did the math inside of our cell. So that's it. That's our function.<br>3:09 CPM function we have created here. We'll be adding some more functionality to it later in the course.

We'll be adding auto complete in the next video and we'll talk about naming a little bit.<br>3:19 That's sort Learn how to sort data effectively in Google Sheets for better organization. Opens in new tab of important at this particular moment. Because the name that you call either custom function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab or the name of the add on will now propagate over.<br>3:30 You'll see we'll use it many, many times. We'll have to put in the marketplace. We'll have to put it here.<br>3:35 I thought this was the one thing. We'll get to it. I thought this was the one thing that I think is important now.<br>3:41 Before we get too far.

But if you want to do more coding, again, this vid, this course is not about the coding.<br>3:47 If you want to do more coding, I have a couple of videos in this about other additional concepts of coding.<br>3:53 And also spreadsheet Dive into the basics of spreadsheets and their features. Opens in new tab automation 101 is a video is a course that literally teaches you how to code in Google sheets.<br>4:00 And then I also have a very quick course called learn. Under coding Google sheets, which is a crash course, 40 minutes and you're done.<br>4:07 But this one, now we have a custom function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab .

But we want to be able to use this a little bit better.<br>4:13 So you'll see that in the next video, how the CPM right now is an unknown function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab . And we don't want that.<br>4:18 We want it to be a known function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab . We want it to work as an auto complete. As a native function Understand the concept of functions in Google Sheets and how to create your own. Opens in new tab , just like any others, just like cost sign and just like if all have all this auto complete, we'll do that in the next video.</div>