An example showing how to query Azure Digital Twins from within PowerBI. You could use this to query the current state of your IoT devices, for example, to use the Anomaly Detector cognitive service to check the state of outliers.
powerbi-adt is available under the MIT Licence.
- Create an Azure Digital Twin
- Give yourself access to the data plane - add some example data - the Azure Digital Twins explorer example data is a good start.
- Create a virtual environment for your Python setup, e.g.
python3 -m venv .venv
- Install the requirements
pip install -r requirements-dev.txt
- Copy the path to your venv
- Enable python scripting in PowerBI
- Log in to Azure on the CLI with
az login
- Import the powerbi-query.py as a PowerBI datasource
query_expression = "SELECT * FROM digitaltwins"
query_result = service_client.query_twins(query_expression)
twin_list = pd.DataFrame(query_result)
The example query I provide in the query_expression
variable will allow you to query the twin graph - and you can use the Azure Digital Twins query language to build on this. Each individual pandas dataframe will appear as a data set in PowerBI.
You should see something like this...
- Using Python as a data source is only refreshable on PowerBI Desktop, or by using an on-premises data gateway in personal mode.
Feel free to contact me on Twitter. For bugs, please raise an issue on GitHub.
Contributions are more than welcome! This repository uses the GitHub flow - and you can choose to use Commitizen to support the use of semantic commits. (npm install -g commitizen cz-customizable
and then git cz
- easy!)