How To Bring AI Into Your Productivity Apps
AI can make you unbelievably more productive, but that productivity could be improved if you didn’t have to leave your app to go to another page. And you’ve all seen videos where ChatGPT solves Excel problems, writes code, or explains code.
To do that, we have to go to the OpenAI platform, ask it what we want, then copy and paste it into our application. So this video is not that type of video. This is where we’re going to bring AI inside our application, right? So that’s what I did here. I brought it inside my Excel file so that I can ask a question in a cell and get the reply in the next cell. If I happen to ask it a question like “Give me the names of The Sopranos cast,” it puts it all in a single box, and that bothered me. I want to put it in multiple separate rows, right, because it’s easier to take that information and then work with it in Excel. Of course, we don’t want to have to do this manually, so I decided to build on this. Whenever ChatGPT’s answer is more than a single line, we’re going to get a multiple-row version of it as well. You have no idea how excited I was when I got this code to work. I’m going to show you how I set it up, and the purpose of this video is to inspire you and show you the possibilities that are out there. Let’s go.
Bringing AI Into Excel
Okay, so over here on Excel for Desktop, I’ve created this simple layout, and in this box, I can ask my question. So let’s say I’m talking with my colleagues, what the top 10 hip-hop songs of the 90s were. Okay, so then we click on “Ask,” and this is where my script is running. The moment I click on this, notice on the side pane here, we get Script Run Status. This is based on Office Scripts. I’m going to show that to you in a second, how it works. Once we get the answer from the AI back, we put it in this cell. Oh yeah, these were my party songs. Let’s do another one. Let’s say we’re discussing what the names of the Spice Girls members were. Do you remember the Spice Girls? Do you know what they were? Let’s see if the AI knows. These are the names we got. Let’s include their nicknames as well because they did have some weird, strange nicknames like Scary, Baby, and others.
Using AI To Solve Excel Problems
Now, let’s say I finally decide to get some work done, but I’m stuck. I can’t figure out this formula that I need to put in here. So here’s what I want to do. I want to grab the total revenue from either the Health sheet or the Productivity sheet or the Game sheet. I have different sheets here. They have a similar structure. My revenue is in column B. What I wanted to do is write a SUM function here that looks into the correct sheet. So, if this is Game, you should go to the Game sheet and grab the B column. If it’s Productivity, you should go to the Productivity sheet. I don’t want to write an IF function because I am going to have a lot of different sheets. I can’t figure out the formula, but ask our AI. Okay, I’m just going to pin this in place and start with “I need an Excel formula. I need to get the sum of column B from different sheets. Now, the sheet name is in cell A2.” Okay, so this is very specific to what I need and I want it to give me the formula. So, let’s ask our AI and see what we get. Okay, so we get: “Assuming the sheet name is in cell A2, you can use the following formula.” Well, this looks good. Let me just copy this, go to my sheet, and paste this in. Okay, it looks like everything is in order and I get a number. Does it really work? Let’s sum up Game revenue. What’s our total? 210,616. That’s what we get. So, if I change this to Productivity, 162,643. Let’s just make sure that it works. Yes, it works. It gave me the right formula. This saved me a lot of time of having to go through different websites, different forums, and blog posts. I got the answer that I wanted by just asking.
Analyzing Data With AI
Now, let’s say my boss asked me to analyze the balance sheet for BMW. So, I can find their balance sheet on the web here and I’ve done my task, I’ve analyzed it all on my own, but I want to get a second opinion from the AI and see what it has to say. So, I’m just going to copy everything, go back here, paste it in, and let’s just go all the way to the top and tell it what we want it to do. We want to analyze the balance sheet and tell us what it thinks the risks are. Okay, so let’s ask. Okay, so we get a response: “The balance sheet includes the following: a high level of intangible assets, which could be a risk if the company’s business model changes. The company has a large amount of debt and the company has a large number of receivables, which could be a risk if the customers don’t pay.” Now, you can run this multiple times and you are going to get different responses. You can use these to cross-check with your own response, but of course, don’t take what the AI says as the truth. You are responsible to cross-check these and come up with your own informed decision. We can also use the AI to quickly give us some data we can work with. For example, we want to get the top 10 countries by area. Let’s ask and see what we get. Okay, so we get our list here. Now, everything is inside the same cell. That’s where this part comes into play. So, I’ve updated the script so that whenever the result is more than one line, we get it into separate rows and we get it on this sheet here. This makes it easier for me to work with the data in Excel. If you’re for example, giving some training, and you want some fake data, you can ask it as well. So, for example, we want to get sales data and budget data from January to December for a fake company. Format should be month, actual sales, and budget sales. Let’s ask and see what we get. That’s our data right here. Now that we get it into separate cells, it’s easier to work with. Now, you can also update the logic to account for the delimiter. It’s just that you can get different delimiters back from the AI, but if you have it in this format, it’s really easy to split it into separate columns. You just have to go to the “Data” tab, here, “Text to Columns”, select the limited, go next, and then select the type of the delimiter you have. So, here is a comma and a space, Finish, and we have our data in separate columns. Now, I can use this as fake data for my training. If you’re a teacher, you could go with a prompt like this: “Give me names of the Breaking Bad characters, add a fake school subject and fake grade, and grades should be in percentage.” Click on “Ask”, and that’s what we get. Tuco Salamanca is not bad in math. Notice here, the delimiter is different here, but we get them into some separate rows, and then again, we can use Text to Columns or Power Query or TEXTSPLIT function if you’d like to split this into separate columns. So, I hope these examples give you some ideas on how you could use AI to speed up your work.
Setting Up AI in Excel
Now, let me show you how I’ve set this up. So, this setup consists of two main ingredients: Office Scripts and an API for GPT from OpenAI. Office Scripts was first introduced for Excel on the web, but recently, we got this Automate tab in Excel for desktop as well. So, this is the Office 365 version. The advantage is that, whenever you automate your tasks using Office Scripts, that automation is going to work for Excel Desktop, it’s going to work for Excel on the web or if you use Excel in Teams, it’s going to work in all places. The second ingredient is an API for GPT from OpenAI, and to get that, you have to go to the OpenAI website, then click on API, set up an account if you don’t have one, and then you can get your API key. So, if I go to my account here, go to your account, and then you can generate your secret key. This is currently free for up to three months, depending on your usage. After that, you’re going to need to upgrade. The API key you get is for GPT-3. So, ChatGPT is a version of GPT-3. It was fine-tuned for conversation and dialogue. GPT-3 is broader. Now, once you have that, you can go ahead and check out the documentation. There are guides on how you can use this API, how you can make requests, and so on. Right, so have a read through this, then you get some ideas on how you can integrate this into your own models. Now, once you have this, you can go over to Excel and create a new script, and you can also do this for Excel on the web if you don’t have the “Automate” tab yet in Excel for Desktop. The script you write is called “Office Script”. Office Script is written in TypeScript and it’s a superset of JavaScript. The script is saved on my OneDrive, you can also save it on SharePoint. The starting point of any Office Script is the “main” function, and here I’m using an asynchronous function. This allows the code to run independently of other code. We’re also using “ExcelScript.Workbook”, so that we can communicate with the Excel objects. We need to provide the API keys. I’ve defined a constant for this. This is where you would be pasting it in. I’ve pasted it inside a cell in a sheet that I’ve hidden. Next up, I’ve defined some more constants. So here, we have “mytext,” this is cell B2. So, this is the “Ask,” what we’re sending to the AI. And down here is the communication with the model. We’re sending the text to the AI model and then here, we’re getting the output back. The output is what we paste back in cell B4, right here. You can use the documentation on OpenAI to help you set this up. And in my case, I got stuck and I asked ChatGPT for help and it was able to solve the problem. So, this part was a collaboration with ChatGPT. We got it to work. Then, I went on to add this part that allows me to check whether I have more than one line, and if I do, it’s going to split it and paste it into separate cells. So, this is where that happens. We are using the “Split” function. This basically splits the string into a list of smaller strings and puts it inside an array. Then, we loop through that array. For each instance, I’m checking whether the array length is greater than zero, and the reason I’m doing that is because sometimes the AI returns empty lines in between, and if I don’t account for this, I end up having empty rows here, and I don’t want that. I just want my rows with text to be below one another. OK, so that’s basically the script, and you can build upon this as you need. I so wish I had this when I was starting to learn Excel. There were times I could spend hours just getting my formula to work. Let me know what you think. I personally enjoyed this experiment just to see the potential we could have in Excel. Who knows, maybe in the future, we can ask it to import the data from Bob, summarize it, and then send it to the boss. Right? Something to look forward to. But let me know what you think. Comment below. I hope you enjoyed this experiment, and I’ll catch you next time.
Grab the files from here 👉 https://pages.xelplus.com/chatgpt-in-excel-file
For more ideas on using ChatGPT to boost productivity check out our "Quick Wins with ChatGPT" course: https://link.xelplus.com/yt-chatgpt-course 🔥use coupon code YTGPT at checkout to get 30% off – available for limited time 🔥
If you get the following error: "Line 46: Cannot read properties of undefined (reading ‘0’)" – It's probably because the API key was not input in the right place or is incorrect – or you need to update the gpt version used. Please double check on OpenAI or create a new API key.
API keys generation needs phone number verification and it is not currently working with IRAN! But your course is great, Thank you!
if u want much higher level AI and accurate and complex guys I'll introducing AI CHAT DEEPAI the AI CHAT DEEPAI is so powerful and much better than OPENAI since start 1990 and u can show ur picture and video and anything u want
I am getting an error – Line 46: Cannot read properties of undefined (reading '0')
Fuck this video is horrid, can you just go straight to the solution without piss farting around for 10 minutes…
how to get Office Script? is that only available through the full MS 365 version? Didnt even see it under the Add-In options?
mantap
Hii. Analyze data button is not showing in Excel Microsoft 365 and in file menu get add-ins option is also not showing. Can you please tell me how do I get that ?
je bent geweldig🤩
Getting error "Line 46 : cannot read properties of undefined (reading '0')
Please assist
Great work! I dont have the automate tab in my Excel. Which version I should I get to have that Automate Tab. I am Project Manager so I would like to use AI in my excel it will make my life whole lot easier. I appreciate your help.
I am using Excel 2021 but I am unable to find the option of Analyze Data. How can I get that option in my excel. Can you tell me ?
I know I'm late to the game, but not everyone watching this video has the same level of skills/know-how when it comes to Excell. You might want to start by explaining how did you add an ask column in excel?
damen garm baba . du er kjempeflink LEIa :-*
The script is running,however when you ask a question,there is no answers reflecting by AI
there is an error while we run the office script you have put up in the line
"const text: (string | boolean | number) = json.choices[0].text;" and it says
Line 46: Cannot read properties of undefined (reading '0')
Please help leila
Light 💡 bulb has been turned on in me
the downside of this is it frequently makes your MS excel run too slow and lots of lags
I don't have automate tab, can I use a code in vba to have such dialog box of gpt
awesome video. the file used to work, but now i am getting an error when running the script. Line 46: Cannot read properties of undefined (reading '0') . I appreciate any help
Nice..but..real problems come when you're working with big files with 10 or 20 columns, full of formulas. In this case, when you have to deal with complicated issues, there you need an assistant. I don't think you can simply copy and paste the entire file in the box, because in this case i'm not sure if ChatGPT can really understand all the links and formulas behind the file…am i wrong or is there a solution? thanks
You might as well speak Chiense.
Can you please make a video that shows beginners how to write a script step by step? When I added your script, it gave me an error message for line 10 🙁
HI Leila, why can not see the automate tab? I have Microsoft 365.
this seems complicated, Microsoft CO-Pilot will replace everything soon it will revolutionized the way we work, A game changer in many ways.
Answer to "Line 46: Cannot read properties of undefined (reading ‘0’)" – you will have to pay in order for this script to work, lowest amount to charge your balance is 5$ to. Nothing's free my friends – "When your credit balance reaches $0, your API requests will stop working. Enable automatic recharge to automatically keep your credit balance topped up."
I confirm that paying 5 bucks solves the case and the script works. I'd add this information to pinned info.
Thanks!
Thank you! This error displays: Line 46: Cannot read properties of undefined (reading '0'). any idea why?
Works great! Thank you for sharing. I had a little trouble initially locating that UNICHAR(96) character. Also, for some reason one line of code was giving me trouble in my version and not in yours (// get generated text part).
Thank you, thank you, thank you! This will save me untold hours of research. You are amazing Leila! You provide quality information that is much appreciated.
You did a greatest showcase about ChatGPT what I'm looking for, thanks a lot!
i dont have automate tab in my excel what can i do?
set up is on 7:29 of the video
you donkey, you never showed HOW YOU BRING AI INTO THE FILE. HOW DO YOU BRING THE AI INTO THE EXCEL FILE? DONKEY!!!!!!!!!!!!!!
Is there a way to do this same thing but through Power automate?
where do you put the API key?
This is an error I'm countering while running the script
"Line 4: Cannot read properties of undefined (reading 'getRange')"
Why didnt you do it with python? I thought python was design for this a little better then typescript?
Awesome video and great idea!!! My mind is spinning with ideas on such applications! Just impressive!
Beyond its state-of-the-art security technology, the Utopia P2P browser shines for its exceptional functionality. By integrating the chatGPT neural network, it simplifies and enhances the online experience for users, eliminating the need for multiple tabs.
Huge thank you, Leila!
The 1/3 creator's of word program the last 6 months i been woring on your project it ashamed just like stealing the program or shall i say snowballing friends surly you have ideas of your own or maybe pay people like me no you rather take well i do like excel just promote it now i dont back theifs