In a world where businesses interact with customers across multiple regions and languages, analyzing multilingual content is no longer optional; it’s essential. Whether you’re collecting feedback, managing leads, or reviewing support tickets, knowing the language of your data opens doors to better automation, routing, and personalization.
As we know, Power BI itself does not have inbuilt functions to detect the language, but this can be achieved with the help of Python Scripting.
This blog walks you through how to implement Automatic Language Detection inside Power BI using Python scripting with no external services required. We’ll consider the real-world scenario below to showcase the above functionality:
Many CRM systems like Dynamics 365 Sales collect lead descriptions, inquiries, or comments from global web forms, campaigns, and events. This information is collected in different languages.
Here’s what you can do with language detection in Power BI:
Capability | Scenario |
Auto-assign leads by language | Route Spanish inquiries to Spanish-speaking sales reps |
Analyze conversion by language | Discover which regions or languages convert best |
Localize engagement strategies | Adapt sales scripts and materials to match lead language |
Filter dashboards intelligently | Allow sales managers to analyze leads by language group |
Follow the below pre-requisites steps to Automatically detect the language using Power Bi:
- Click on the setting icons as shown below:
- Go to Python Scripting and add the Python directory. If Python is not installed, then install Python from Welcome to Python.org and add the directory. Once done, click ok.
Once the pre-requisite steps are done, follow the below steps to Automatically detect the language using Power Bi:
- Open Power BI desktop and create a blank report.
- Click on the Dataverse connector, select the Leads table from your environment, and then click on Transform Data to proceed with data shaping.
- Do required transformations like selecting the columns, remove duplicates and other transformations.
Once done, click on the Run Python Scripts option.
- Paste the below code in the Python script and then press ok.
# ‘dataset’ holds the input data for this script
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["subject"].astype(str).apply(detect_language)
- Click on the expand option and select the fields that are needed, as shown below:
- Now, a language column is created that detects the language of the subject.
Since all the transformations are completed, we can now proceed with creating the report. We have created the report below for our scenario:
Now, based on the above report, we can achieve the following:
- Filter dashboards intelligently based on languages.
- The sales manager can assign a lead to the appropriate salesperson. For example, Route Spanish inquiries to Spanish-speaking sales reps.
- Can do more analysis by adding bar charts. For example, discover which regions or languages convert best.
Conclusion:
By combining Python and Power BI, you can add a powerful layer of intelligence to your lead analysis, helping sales teams become more efficient, more localized, and more responsive. Language detection is just one example of how you can bring advanced automation into everyday sales workflows.