Calculate Reading Time with Custom Function in Google Sheets
Learn how to create a custom function in Google Sheets to calculate reading time based on word count and words per minute, enhancing your spreadsheet capabilities.
We have text here and we don't want just word count. We want to find out what is the reading time. So we're gonna need to calculate how many words and figure out pretty much average words per minute and do that math. But we're gonna do it in a custom function so that we can just type in equals reading time or something like that. Or time to read. Time to read. And we're gonna have a custom function here. Let's go do it. Extensions app script . We can call it reading time and we're going to create a function here called Time to Read. This could be also reading time. Doesn't matter. And we want two things in our function , which is text and words per minute. Now this words per minute is gonna be optional, but we'll
put that in the app script here. So we are going to get error of a zero divide by zero sort . So we want to say if there is no text, then we're just gonna return, let's say nothing. I spelled return correctly. So that's one thing. And if there is no words per minute, then our words per minute is equal to 2, 3, 8. I just looked at is the actual average reading time to variable. Now we need to actually count the words, so we're gonna take all the. Text here and find out what's the variable words or word count, or we can take the text, trim it so that we don't have any extra spaces at the beginning or end. I'm gonna split it. This looks a little weird, but it's slash slash other slash s plus slash. And then we're gonna take all of the that splits and just find out
how many are there, so that length, and then we know how many minutes it is by doing words divided by words per minute, and. So we wanna make sure that we round this 'cause maybe it's minutes and seconds. So we go mins equals math floor and we'll put minutes here. Variable seconds. We can say minutes here or seconds. Math round and inside we're gonna do minutes. Actually that is an S there. You just want to use a new variable. Mince, not minutes. So six minutes minus, mince, what is that like floor one and then times 60. We are going to return a phrase, which is Mins plus Space.
Space and put minutes there, plus seconds, plus space sec. Seconds to read. If you need to do a couple more things here just in case, if means is equal to zero, then we'll return just the seconds, plus seconds to read, and if seconds is equal to zero, we wanna return just. Minutes plus space. Minutes to read, see. So basically at the end, we're going to either have two numbers or only seconds or only minutes, and we're gonna return any of those three at the very top. Let's make this a custom function by doing slash and two asterisks at custom function . Let's save this and go check it. So equals
reading time. See it's already there in the auto complete. We'll do a two and words per minute will leave blank. Three seconds to read. Let's say we read very slowly. A hundred words per minute. Very different. Right? And there we go. We had also minutes and seconds. Cool. But I wanna do one more thing for our custom function because as we're writing this, we don't see that words per minute is optional, and we see in this example, object. Object. So let's go fix that up and right above our custom function . We're gonna write a description, calculates reading time, and then peram. The first parameter is a string . It's text. Text to analyze or calculate at peram.
And the second thing is a number . I will say WPM, that's words per minute. We'll say Optional words per minute defaults 2, 2, 3, 8. At return. What are we getting out of? This is a string estimated reading time. So let's save all of that. Once it's saved, we should be able to go back to our function reading time. See it says, calculates reading time. If we click on this now, it says, reading time text words per minute, string number calculates reading time, and it says here optional words per minute text to calculate. Now we have more information for our user to be able to do this. Now if we want another name for this, say. We have told people, Hey, we've put a time to read function here, or reading time. We can actually take this entire thing and copy it and rename the copy.
Time to read. Let's save that. Now, we have two identical functions here, but it allows the user. To have one or the other time to read or reading time. Maybe a little complicated at the end, but hopefully this kind of fun custom function allows you to create really cool stuff for yourself or for other users who are using your sheets, even if it's someone like you six months later. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos.
But for right now, right here, one of these videos is gonna be your next Google sheet.