Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Importing Microsoft Fabric Notebook Data into Power BI

Hello everyone,   I created a lakehouse in Fabric. I can access to the files that I uploaded via get data button. I can run my python notebooks, I can transform the data. But I can not access to th...
  • Anonymous's avatar
    Anonymous
    3 years ago

    I found the solution and want to share it step by step.

     

    In Fabric - Lakehouse click on get data, upload files.

    Choose your excel file.

     

     

    Once you upload your excel file. You will see it on your files.

     

     

     

    Click on top open notebook and choose new notebook.

     

     

    Paste below code into your notebook.

     

    # 1 load excel file into lake house via import data

    # 2 import excel file into dataframe, choose path from files ... copy ABFS
    import pandas as pd
    df=pd.read_excel('abfss://ecf5a729-f8d9-417f-ae28-8ed1e9473ce3@onelake.dfs.fabric.microsoft.com/027295a6-aee0-4e87-a2dc-0f89fd816a27/Files/Test.xlsx')
    #display(df)
    # 3 save dataframe into parquet, choose path where want to save file using ...
    # 4 if parquet not installed, will get error, in this case: !pip install parquet
    df.to_parquet('abfss://ecf5a729-f8d9-417f-ae28-8ed1e9473ce3@onelake.dfs.fabric.microsoft.com/027295a6-aee0-4e87-a2dc-0f89fd816a27/Files/Test.parquet')
    #5 read parquet file
    dfp=spark.read.parquet('abfss://ecf5a729-f8d9-417f-ae28-8ed1e9473ce3@onelake.dfs.fabric.microsoft.com/027295a6-aee0-4e87-a2dc-0f89fd816a27/Files/Test.parquet')
    # 6 write parquet into a table, go to lakehouse, from top right click on Lakehouse, change it to SQL End Poin and start using SQL on the table.
    dfp.write.mode("overwrite").format("delta").saveAsTable("N_G_Table")

     

     

     

    As explained and show above, you need to change path in your workspace.

    once you have update tha path, run the code.

     

    refresh your table as below.

     

     

    You should see below table on your Lakehouse.

     

     

     

    Open Power BI Desktop. You can choose lakehouses but it gave me error at the beginning, in this case click directly on OneLake data hub on Home tab.

     

     

    Choose your lake house and click connect.

     

     

    Created a basic chart to see that data has been loaded into power bi.