Academy ↓
Hey there stranger!
Sign up to get access.
Create a CPM Custom Function (Create Better Calculators!)
About this Tutorial
Sheet Resources
Video Transcript
00:11 Uh, one of the concepts that I tried to share with you in better sheets, if you're trying to sell a sheet is, uh, to try to create calculators that we use ourselves, but mainly you might be using calculators yourself only, not even thinking about selling a sheet or giving this away to others.
00:29 But I think actually this is useful for both cases. One to clean up your sheets from messy sort of calculators, where you have a form and then have that information.
00:39 But also if you ever want to sell your calculators or calculations, uh, I think custom functions are a really fun way to do it.
00:47 Uh, I think it was a really neat thing to do because it makes essentially just like you have formulas, like some, and like average, you can create your own formula.
00:58 That's customed to exactly what you need, but let's do this with our CPM, right? CPM is a very common thing we do in marketing in a lot of places, creators do need to figure out their own CPM.
01:12 Uh, if they are running ads, if they're going to try to create a CA uh, if they're going to try to create a rate for themselves, they want to know what their own CPM is.
01:22 So CPM is cost per milli. That's going to have a cost like $500, and it's going to have some kind of like opens or page views.
01:35 And we're going to have, like, let's say 45,000. So our CPM is going to be, how are we going to figure this out?
01:42 We're going to do equals 500 divided by this cop, the thousand, this divided by 1000. Now we have $11. So if we take this $11 and we go equals 11 times 45,045, pretty close, right?
02:04 This is probably means a couple. There we go. $11 and 11 cents pretty darn close, but we don't need this number.
02:15 Right? We have this number is cost, but we just want to double check that, right? That this calculation is correct.
02:20 We take the cost divided by the page. We use divided by a thousand. So this is pretty typical, right? You create a form sort of view.
02:31 You have three columns, not three columns, three rows or columns. Sometimes you'll do something like this cost page views and your CPM.
02:46 And we'll do this. We have to move this over here, but the reference messes up. So we do equals cost per divided by 45,000 divided by one.
03:00 There we go. So maybe it looks something like this, right? Where you have different columns. This takes up a lot of space.
03:07 When in reality, if we knew, okay, we know this calculation, we could do this in Google app script. Let's do that.
03:17 Right? And we can put this down to exactly. Sort of just one word, right? We can say equals get C PM, and we can enter a cost, whatever that might be, which would be like B two comma, and then the, uh, page views C two.
03:35 And wouldn't that be cool? Right? But we don't have a function yet. Let's make one. Let's go to extensions app script.
03:48 We're opening our IDE our custom function is going to be named, get CPM. We can actually just say CPM. Nope.
03:56 Okay. CPM. Yeah, we can, can do CPM all caps. Now we need a cost comma views. Let's say we're just going to do page views.
04:08 All right. Now we got a return. The cost divided by views divided by 1000. So now remember we put in the text, we just tried to do this quickly and we did get CPM, but in our function, it's called CPM.
04:31 So let's go and edit this CPM. If you got to load, there we go. $11 and 11 cents. So we got the answer without having to show the calculation, right?
04:44 We only have the calculation here in our, uh, code. Now, a few caveats, right? What might happen is you might forget this calculation.
04:53 You might forget how does this work? We sometimes want to keep a formula within a cell so we can easily reference that and see if it's correct.
05:03 Right? But CPM is a fairly common calculation. Uh, if you don't, if you get it right the first time you're going to get it right each time.
05:12 So this is really good to have suffocate, to abstract away the math, uh, and be able to check it. If you do know how to get to extensions apps, there's one other thing that we want to clean up.
05:24 And I think Google sheets and Google script makes a really cool thing here possible. So let's say we have Another, uh, yeah, that was a dollars for 80,000 page views.
05:41 Then we want, we know there's a function here, but we forget. Let's say we forgot the name, CPM the three words.
05:46 And maybe we didn't create that. But if we go equals C you notice that normal functions, normal formulas show up here, but our CPM does not.
06:00 But Google script makes a really cool option for us to do over here and custom functions in the help screen.
06:08 At first, it shows us just how to create these custom functions. But it also, if we scroll down a bit of their help section, it shows us that him copy this text and it will allow us to auto complete.
06:22 So let's copy this just above this function. Now we just need to edit this text because let's look at exactly what I just put in here.
06:31 Let's save it and see what happens. We go equals C P. Now it shows up, but it gives us the wrong information.
06:39 It says, multiplies, the input value by two that's incorrect. What it does is actually right here gets costs per VLA.
06:53 And now we want to know like, how do we use this, right? How do we, what, what inputs do we need?
06:59 Because maybe we are not the people to use this. Right? We want to know cost and views. So we can do something like cost view.
07:12 We have return CPM, perimeter, cost views, put the costs and views. And then we save this. Now let's go back, go equal CP.
07:37 Now we have exactly what we need. Now we know right here without going to our extension, right. App script, without going here, we know what we need to do.
07:48 Okay. Cost views. Oh, this is perfect. Right? Cost is going to be B3, karma C3 for page views. And now I don't have to reference this script.
08:02 It is now told to be here and told to any other users. But what I really love is the potential of this, right?
08:10 There are over 400 formulas. If you go equals all of these, these there's over 400 of these. Most of them we don't use, right.
08:22 I use Google sheets a lot, and I don't use all of them, nearly all of the meal. I don't even use a majority of them, but what this allows us to do when we write custom functions is allows us to get a little more granular and very specific to our own needs.
08:39 And also our company's needs, our employee's needs, our employer's needs. Right. We can create custom functions here for our boss.
08:46 Uh, let's say they love to, you know, write some extra texts or add something. This doesn't just have to be, uh, numbers.
08:55 Right? We can frame messages, function. Um, let's say get message. And we're going to just say, or get email let's let's actually make the message and email, get email, email accounting.
09:14 Um, we can return text and we can just say accounting, AC, maybe it's difficult. actt@google.com right now. What happens when we write that function right now, this moment, we need to remember this text, right?
09:33 We go, here we go. What's that email, if we can go get okay. I forgot what it is. What is it?
09:40 Get email accounting. It'll load a little bit. There's our email address, but put this custom function above it. Get email for accounting parameters.
09:58 We'd have nothing return. We might even just put that there just it's fine. Let's make sure it saves. And now we go equals get email accounting, get email for accounting.
10:20 Bam. We got an email. This is cool. We can actually save functions here as just text or text as functions here.
10:29 We don't necessarily have to only do math. This is really cool. I F I find this fascinating and fun, and I hope you do too.
Courses
Sheet Stories / Video Notes + ADDED: Email Notifications
00:00:00
Fast FAQS
ChatGPT Clone in Google Sheets Part 2
Create an Internal Google Sheets Add-on
Why Different Cell References in AI Integration in Sheets?
Show Sheet Tabs Based on Edit
Add Title Case to Google Sheets
Getting Started Coding in Apps Script
How to Power Testimonials with Google Forms and Sheets
Seek Errors When Coding Apps Script
Think Like a Programmer: Develop The Mindset of an Apps Script Coder
ChatGPT Clone in Google Sheets Part 1
Embed a Number in a Website from a Google Sheet
Create Navigation Like A Book or Presentation
Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet
00:29:08
Hold a Giveaway Raffle in a Google Sheet
Quickstart Tutorial OpenAI API in Google Sheets
Capture Emails from Website Form to a Google Sheet (Without Zapier)
Embed a Headline in a Website from Google Sheets
Create a new Spreadsheet from just a Name in a Sheet.
00:05:21
Bjarne Asks: Can I show the Last Time of the Last Edit in a sheet?
00:05:43
Email Yourself a Cell from a Google Sheet, Every Day
OpenSea Data Inside Sheets
Create an Email Campaign Stats Calculator
00:35:13
Twitter App Clone in a Google Sheet
Dylan Asks: How to Automatically Delete Rows If Cell Contains Value
Highlight Row as You Move Your Cell Selection
Create a Timer with Apps Script
LinkTree in a Google Sheet
00:11:22
Password Protecting Data In a Google Sheet
Automatic Weekly Backup of Google Sheets
Create a CPM Custom Function (Create Better Calculators!)
Move Entire Row when a Cell is changed to "Yes" - The $75,000 Google Script
00:12:29
What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users
Sync Two Tabs Without ImportRange()
Google Sheets Stories? No! But we'll add timestamped video notes to your google sheets.
00:00:00
Password Protecting Data In a Google Sheet Part 2 The Basics
Benoit Asks: How to Convert Case
00:07:35
Learn to Code in Google Sheets, For Programmers
Add a Checkbox to Turn on Dark Mode
00:05:10
Write Your First Script
00:08:31
Find Keywords in Any Column. Create quick search dropdown to find keywords
00:09:37
Basic CRM - Add a Powerful Script To Move Row Based on Status
How To Improve: 1,000 Business ideas: Business Idea Generator
00:11:20
Let's Make a Bookmarklet!
00:12:37
Troubleshooting Bitly in a Google Sheet Script
00:07:07
Unique Features - Design a Better Dashboard Part 2
00:04:13
How To Set Up Stripe Webhook to Google Sheets with Google Script
00:22:10
How to Edit a Macro
00:08:22
Sheet Stories / Video Notes + Clear 24 Hour Old Videos
00:35:10
Add A Timestamp to Task Lists (without Now Formula)
00:07:44
Make your Custom Functions Like Native Functions | Custom Function Autocomplete
00:17:58
Create a Changelog Between 2 Cells Custom Function | To learn Double For Loop
00:23:26
New Syntax for WhatChanged Formula in Google Script
00:07:14
How to Record Macros
00:06:20
2 Ways to Delete Lines Quickly (CAREFUL, it's a script!)
00:09:53
Deep Inside Dark Habits Google Script
00:18:54
How to Trigger Macros Daily
00:06:58
5 Ways to Create Coupon Codes | Create UUIDs
Create a Radio Button From Checkboxes Using Google Apps Script
00:15:01