Forum Discussion

uk-roberto92's avatar
uk-roberto92
Frequent Visitor
1 year ago
Solved

Recording PBI table into SQL server

Hi,   I have a data model in Power BI with a final table containing columns that are built using conditions depending on other linked tables.   I was wondering if there's a way to record a snapsh...
  • v-hashadapu's avatar
    v-hashadapu
    1 year ago

    Hi uk-roberto92 , Thank you for reaching out to the Microsoft Community Forum.

     

    Yes, you are on the right track, If you have access to Microsoft Fabric and are comfortable with PySpark and wants maximum scalability. Create a Fabric Lakehouse and a Notebook. In the Notebook, use PySpark to query your Power BI dataset directly with mssparkutils.notebook.pbi_query, passing EVALUATE FinalTable to load the full table into a DataFrame. Export it to SQL Server using the JDBC connector with an overwrite mode to ensure a fresh snapshot. Set up a Fabric Data Pipeline, add the Notebook as a task, and schedule it. This bypasses REST API row limits, making it ideal for large or complex datasets. However, it requires Fabric licensing and PySpark knowledge, so it’s only worth pursuing if your dataset exceeds 100,000 rows or Power Automate’s setup feels limiting.

     

    For the most reliable and immediate solution, I recommend using Power BI Service with Power Automate. Since you’ve confirmed DAX Studio works for a manual export, we’ll build on that. Publish your report to a Power BI Service workspace and schedule a dataset refresh. Create a Power Automate scheduled flow to run shortly after. In the flow, use the “Power BI - Run a Query Against a Dataset” action with your DAX query, EVALUATE FinalTable—to export the full table as JSON. Then, use the “SQL Server - Insert Row” action to parse the JSON and write it to a pre-created SQL table (e.g., PowerBI_Snapshot). For datasets over 100,000 rows, add pagination by modifying the DAX with TOPN and an offset loop in the flow. Publish the workspace as a Power BI App for access. This is fully automated, leverages your existing tools, and requires no extra licensing beyond Power BI Premium (if already in use). It’s efficient for small-to-medium datasets and scalable with minimal effort.

     

    If you have access to Microsoft Fabric and are comfortable with PySpark, I suggest an alternative for maximum scalability. Create a Fabric Lakehouse and a Notebook. In the Notebook, use PySpark to query your Power BI dataset directly with mssparkutils.notebook.pbi_query, passing EVALUATE FinalTable to load the full table into a DataFrame. Export it to SQL Server using the JDBC connector with an overwrite mode to ensure a fresh snapshot. Set up a Fabric Data Pipeline, add the Notebook as a task, and schedule it. This bypasses REST API row limits, making it ideal for large or complex datasets. However, it requires Fabric licensing and PySpark knowledge, so it’s only worth pursuing if your dataset exceeds 100,000 rows or Power Automate’s setup feels limiting.

     

    For a quick manual option that’s already tested, stick with DAX Studio. Connect it to your Power BI Desktop model, run EVALUATE FinalTable, and export the results to a CSV file. Then, use SQL Server Management Studio (SSMS) to import the CSV into your table. This is perfect for one-off snapshots and requires no setup beyond what you’ve already done. However, it’s not automated, so it’s only a stopgap while setting up one of the above solutions.

     

    If this helped solve the issue, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details, always happy to help.
    Thank you.