Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered
Power BI is an exceptional tool for data analysis, but its true potential is unleashed when we integrate Power Query with Python. This combination allows us to automate tasks, enrich data, and conduct advanced analyses effortlessly. In this blog, we’ll walk you through a real-world use case that showcases the power of Python in Power Query: automatic language detection for customer reviews!
Power Query provides robust transformation capabilities, but it lacks built-in language detection features. Python, however, offers powerful libraries that make this process straightforward. By combining both, we can automatically determine the language of text-based data within Power BI.
Before we begin, ensure that Python scripting is enabled in Power BI:
Open Power BI Desktop.
Go to File > Options and Settings > Options.
Under Global > Python scripting, select your Python installation path.
Click OK.
For more details, refer to the official guide: Run Python Scripts in Power BI Desktop
Imagine we have a database of customer reviews written in different languages. For more advanced analysis, we want to automatically identify the language of each comment. We can use Python to solve this problem easily. Let's go step by step!
We’ll need two key libraries:
To install them, open your command prompt and run:
pip install langdetect pycountry
Imagine we have the following dataset of customer reviews: (Excel file attached):
Our goal is to automatically detect the language of each comment.
In the Python script editor within Power Query, insert the following code:
from langdetect import detect, DetectorFactory
import pycountry
DetectorFactory.seed = 0 # Ensures consistent results
def detect_language(text):
try:
lang_code = detect(str(text)) # Convert to string to avoid errors
language = pycountry.languages.get(alpha_2=lang_code) # Get full language name
return language.name if language else "Unknown"
except:
return "Unknown"
dataset["Language"] = dataset["Comment"].astype(str).apply(detect_language)
dataset[["Customer", "Comment", "Language"]]
Click OK and Power Query will execute the script.
After running the script, Power Query initially returns a single row containing a table object. To extract the results:
🎯 Final Output:
This example illustrates how Python extends Power Query’s capabilities, making it possible to detect languages automatically within Power BI. The same approach can be applied to:
✅ Sentiment Analysis (positive/negative reviews)
✅ Automatic Translations
✅ Text Summarization
🔥 Try it out in your next Power BI project and unlock new analytical possibilities!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.