Power BI setup

Python Visual

Power BI supports running Python visual, so you can do all the visualization in python Matplotlib, and powerbi will display the figure from matplotlib.

When install Power BI desktop it will automatically detect the python directory, e.g. c:/users/yourname/anaconda3/

However, sometimes this default python environment might be too recent to work with Power BI. E.g. the python you have is version 3.9 (late 2021) and when you run a simple plot like:

     plt.plot([1,2,3], [4,5,6])

It will show strange errors like:

   failed to import xyz module

And this xyz module is weird, sometime numpy, sometimes pil image, etc.


It is because the Power BI is not updated with the latest python version yet. The solution is to downgrade your python version. This can be done through creating a lower version environment in anaconda.

    $conda create --name py38 python=3.8

    $conda activate py38

    $python -m pip install matplotlib

    $python -m pip install pandas

The matplotlib and pandas are default packages used by Power BI for the visual so better install them.

Then all good!


 Remove Datetime hierarchy

When loading a dataset in, if any column is datetime, Power BI will automatically translate it into date time hierarchy. 

That seems fine, but when you load datetime column into a Python Visual, it actually selects all parts of a hierarchy. So it load, year, month, day, etc. multiple columns while you only need one datetime column.

To achieve that, Go to  File --> Options and Settings --> Options --> Current File -> Data Load  and turn  off 'Auto Date/Time' (under Time Intelligence)

Happy day.