Forum Discussion
DAX standalone query execution using python
- 6 months ago
Hi safrasmusthafa
Thank you for sharing the updated configuration and Python code. Even though the service principal has tenant‑level access, is added to the workspace, and the workspace is running on Fabric (F2) capacity, the 401 PowerBINotAuthorizedException occurs because the REST API executeQueries endpoint does not support DAX execution when using a service principal. In Premium/Fabric workspaces, service principals can run DAX only through the workspace’s XMLA endpoint (powerbi://...), as XMLA is the only interface that accepts application‑only authentication for DAX operations. To execute DAX from Python, you will need to use an XMLA‑compatible client library (such as pyadomd) and authenticate using the client‑credentials OAuth flow with your tenant ID, client ID, and client secret. Once connected through the XMLA endpoint, the service principal will have the necessary authorization to run standalone DAX queries successfully.Regards,
Microsoft Fabric Community Support Team.
Thank you for reaching out to the Microsoft Fabric community forum.
The PowerBINotAuthorizedException (401) happens when a service principal does not have permission to run DAX queries on a Power BI dataset. To allow DAX execution, make sure the workspace is on a Premium or Fabric capacity, since shared capacity does not support XMLA endpoint operations. The tenant setting “Allow service principals to use Power BI APIs” must be turned on, and the service principal should be added to the workspace, ideally as a Workspace Admin for full XMLA read/write access. When running queries from Python, use the client-credentials OAuth flow with the correct tenant ID, client ID, and client secret. Connect using the workspace’s XMLA endpoint (powerbi://…), as DAX queries cannot be run through the REST dataset endpoint. With these steps, the service principal will be authorized to execute DAX queries.
If you have any more questions, please let us know and we’ll be happy to help.
Regards,
Microsoft Fabric Community Support Team.