You are on page 1of 17

Practical guide to

ChatGPT in Power BI

Mathias Halkjær
Principal Architect
Content
1. What is ChatGPT

2. Getting an API key for Open AI

3. Ready-to-use Power Query function to call the ChatGPT API

4. How to use import and configure the function

5. Using ChatGPT on your Power BI data


What is ChatGPT?
Introduction
What is ChatGPT?
Introduction
Should I use ChatGPT here?
Is it fine that the
output is NOT
factually correct?

Yes No

Are you sure that you Do you have the


are NOT about to Yes expertise or capabilities
share any sensitive to evaluate the
data in your prompt? correctness?

Yes No No

Might be a good fit! Not the ideal use-case!


Getting an API key
Getting an API Key
API key to Open AI to unlock the ChatGPT engine

• Go to platform.openai.com

• Create an account, confirm your e-mail, add account details and confirm your phone number

• Click on the profile in the top-left then “View API keys”

• Generate an API key (+ Create new secret key)

• Copy the key. For security reasons, you won't be able to view it again through your OpenAI account.

• If you lose this secret key, you'll need to generate a new one.

Useful links:
🔗 ChatGPT API documentation
🔗 Pricing (openai.com)
Power Query Function
Ready-to-use
Power Query Function
Ready-to-use

let
Output = (prompt as text) as text =>
let
url = "https://api.openai.com/v1/chat/completions",
apiKey = "INSERT API KEY HERE",
headers = [
#"Content-Type" = "application/json",
#"Authorization" = "Bearer " & apiKey
],
body = Json.FromValue([model = "gpt-3.5-turbo", messages = {[role="user", content = prompt]}]),
response = Web.Contents(url, [Headers=headers, Content=body]),
content = Json.Document(response)[choices]{0}[message][content]
in
content
in
Output
Source: https://www.fluxbi.com/blog/how-to-use-chatgpt-in-power-bi
How-to guide
How to import and configure the function

• Copy the Power Query Function

• Go to Power Query via “Transform Data”

• Create a new blank query, paste the function into the “Advanced Editor”

• Replace the text "INSERT API KEY HERE" with your own API key
(e.g. like this "sk-5nEAGEHxZ2QqhUUpIQT3BlbkFJyMx0Tl9bbjKnYDLDlo01")
How to import and configure the function

• Optionally: give it a test drive by writing a prompt to ChatGPT and invoking the function
Using ChatGPT on your data
Using ChatGPT on your Power BI data

Finally, to enrich some actual data with a new column using ChatGPT, repeat the following steps:

• Go to some data of yours (preferably only a few rows)

• Add a new column with the “Invoke Custom Column” button.

• Pick the ChatGPT function. Just start out with some static text.

• Continue on the next slide…


Using ChatGPT on your Power BI data

• Modify the text to your desired prompt, including data from your dataset as referenced column.
(See example)
Voila!
Enjoy!
Mathias Halkjær
Principal Architect

You might also like