Power BI is a great tool to import and transform data from various sources. Exporting data is however more difficult. This Python function returns a Pandas DataFrame from Power BI service, given a dataset id and a table name (or Dax query), allowing you for exemple to save Power BI data in a file or in a SQL database. This method uses Windows identity, also used in Analyse in Excel, and should be used as a quick and convenient way to extract Power BI data. Power BI rest API execute queries should be preferred if you have Azure and Power BI relevant rights.
Requirements
Test if Analyse in Excel is working for a report you have access to
Analysis Services client library MSOLAP should be version 15 (recent version 16 is not working as today)
Install pywin32 via pip install pywin32 or conda install pywin32
Update the code your dataset id and table name (list of tables available via Show tables button on Power BI dataset page) or use DAX code to generate a custom table with measures
The code
Notes
The function uses the connection generated for Power BI Analyse in Excel
The Windows identity of the caller is used to connect to Analysis Services (Integrated Security=ClaimsToken)
Beauty of the solution is avoiding authentification required for premium XLMA and Power BI REST api (you/IT need to register an Azure AD application and I'm still looking for a clear documentation)
I'm investigating the issue with latest MSOLAP client library. Meanwhile, previous version 15.1.108.23 is available here: x64 and x86 (thank you Rahul Tenany for the links)
It was tested on different machines and configurations: more testing and feedback is welcome