by Wyn Hopkins

Streamlining Power Query Code Documentation with GPT-4: A Game Changer

Watch my explanation or read on if you prefer…

 

Introduction

As Power BI and Excel developers, we often find ourselves knee-deep in lines of code. Writing, cleaning, documenting, and renaming steps – it can all be quite time-consuming. The game has changed with the introduction of GPT-4, a powerful tool from OpenAI that can help streamline the process significantly.

We’ve all been there. Our code is handling a variety of tasks, cleaning up data, filtering rows, capitalizing, trimming text, and merging columns – typical power query stuff. Documenting and renaming these functions with meaningful names without spaces used to be a chore, but not anymore.

How to Use GPT-4 for Code Documentation

Setting Up Your OpenAI Account

Setting up your OpenAI account is straightforward. Head to the Open AI website, where you can sign up and access both GPT-3.5 (free) and GPT-4. Although the free version is available, GPT-4’s superior performance justifies its $20 per month cost.

To get the most out of GPT-4, you will need to provide a well-constructed prompt. A good prompt includes instructions about how you would like your code to be laid out.

You can download the prompt I used here:

Free Download

Once you have your prompt ready, paste it into the “Send a message box” and click the send button.

Then simply copy your code from the advanced editor of your Power Query and paste it into the GPT-4 chat and click Send again.

 

The Power of GPT-4

The result? Cleaned up code, detailed descriptions of the overall process, line-by-line comments, flagged filtered steps, and meaningful codes like ‘TrimFirstName’ or ‘CapitalizeFirstName’. This tool will turn a chaotic codebase into a beautifully organised and easy-to-read script.

You can simply click copy and paste into your advanced editor.

Constructing the Right Prompt

The key to getting the best out of GPT-4 lies in the prompt. It’s crucial to instruct GPT-4 to act as an expert in the relevant field (in our case, a Power Query expert). Providing an overview of the task, specific instructions, and examples of the desired outcome will result in a much higher quality output.

For example, if you want GPT-4 to rename each line of M code to something more meaningful and use CamelCase, explicitly state this in your instructions. Similarly, if you want GPT-4 to prefix filtered steps with ‘Filter_’, make sure to include this in your prompt.

Conclusion: Embrace the Future

GPT-4 is truly a game-changer for coding, making tasks like documentation and code cleaning so much easier and more efficient. If you’re looking for ways to streamline your workflow, it’s time to consider leveraging this powerful tool from OpenAI.

Let us know your thoughts and experiences using GPT-4 for code documentation. We would love to hear your feedback and any tips you might have discovered along the way.

*Stay tuned for future posts on other exciting ways to use GPT-4 and other AI tools to boost your productivity!*