Excel 2024: Ask OpenAI Questions from Excel Using Excel Labs


June 05, 2024 - by

Excel 2024: Ask OpenAI Questions from Excel Using Excel Labs

A team of Microsoft researchers in Cambridge England have developed a free add-in for Excel called Excel Labs. At press time, there are three tools in the add-in: The Advanced Formula Environment, a function called LABS.GENERATIVEAI, and a Python Editor.

I recently had a hobby project where I needed to look up the year that 3400 music songs were recorded. I thought of using the Spotify API, but because songs are often remastered, it may not be accurate. The Excel database included columns for artist and song title. Using a concatenation formula, I added a column with 3400 questions similar to "In what year did Benny Goodman originally record the song "Sing, Sing, Sing "?". In this example, the question is in cell C9.


Using the Excel Labs add-in, I then added a column with =LABS.GENERATIVEAI(C9).

It took 10-15 seconds but the answer in C9 eventually came back and said Benny Goodman originally recorded the song "Sing, Sing, Sing" in 1937. This answer is not particularly useful. But with a formula in E9 of =LEFT(RIGHT(D9,5),4)+0, I was able to extract 1937 from the answer.

I waited until I could leave the computer for a few hours. On the Formulas tab, I changed the Calculation Mode to Manual. Then I copied the formula down to all 3400 rows. Finally, I clicked Calculate Now and walked away. When I returned a few hours later, all 3400 questions had been answered.

To avoid asking the same 3400 questions again, copy the results and paste as values.

Here are some important points about this task. (1) It is a hobby project. (2) There was no summer intern I could pay to go look up 3400 facts. (3) If I did not use OpenAI, the project would not have gotten done. (4) No one is going to die if the answers were wrong 10% of the time.

Given those points, it was a perfect way to make progress on a project that otherwise would not have been possible. As I am writing this in January 2024, the chat-bots are still notorious for hallucinating facts. You have to be willing to accept that the answers will be wrong or made up 1 out of 10 times.

My Accounting 101 professor Ward would be spinning in his grave if I offered to rely on something that is wrong 10% of the time. But there are times when 90% accuracy is good enough.

Before you use the LABS.GENERATIVEAI the first time, you need to go through some pre-requisites.

1. On the Home tab in Excel, go to Add-Ins and search for Excel Labs. Install the add-in.

2. Click on the new Excel Labs icon on the far right side of the Home tab. Open the section for LABS.GENERATIVEAI.

3. Follow the instructions for getting an API Key from OpenAI. The first 30 days of use will be free and you will need a credit card after that. As of January 2024, the fees for OpenAI are ridiculously inexpensive. The 3,400 calls to the API cost me sixty six cents. That works out to one penny for every 50+ calls to the service. By changing to calculation to Manual, you can perform all the calls once with a single Calculate Now and then paste the answers as values.

4. While the questions are queued up, you will see a circle icon and the word BUSY! in the cell.

There are a number of settings in the task pane where you can customize how OpenAI should respond. You can override some of these settings using optional arguments in the formula.

Before using the LABS.GENERATIVEAI function, you need to create an account at OpenAI.com and generate an API key.

Hover over each of these settings found in the Excel Labs pane to control the answers that you might get back from the questions.




This article is an excerpt from MrExcel 2024 Igniting Excel

Title photo by Iain Cridland on Unsplash