Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in BI by (17.6k points)

I have to export all data from PowerBI visuals.

I managed to use a library powerbi.js (https://github.com/Microsoft/PowerBI-JavaScript/wiki/Export-Data) and manage to implement the following solution:

report.page("ReportSection").getVisuals()

   .then(function(visuals) {

        return visuals.find(function (visual) { return visual.name === "829c5bdfe33aba301b32" });

    }).then(function(emailVisual) {

        return emailVisual.exportData(models.ExportDataType.Summarized)

    }).then(function(result) { 

        console.log(result.data.length)

    });

However, because the visual (which is a table) uses a lazy load to load all the entries, when I export the data - it only exports records, that are currently loaded into the visual.

To load more data, I need to scroll down the table and call the above code again.

Is there a solution to export all data programmatically at once? 

1 Answer

0 votes
by (47.2k points)
  • When embedding Power BI reports with PowerBI Javascript API, There's an event called "dataSelected". It can capture the selected data. eg, when clicking on a histogram, the selected data gets captured.

  • Whenever we click on a table visual, there no such event triggered. A working solution is using a column chart that shows the same data in your table visual

  • This  PowerBI Javascript API can be applied to embed reports from both Power BI Service and Power BI Embedded.

<html>

  <script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/jquery/dist/jquery.js"></script>

<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/powerbi-client/dist/powerbi.js"></script>

     

<script type="text/javascript">

window.onload = function () {

 

var embedConfiguration = {

    type: 'report',

    accessToken: 'yourToken',

    id: 'yourReportID',

    embedUrl: 'https://app.powerbi.com/reportEmbed'     

}; 

var $reportContainer = $('#reportContainer');

 

var report = powerbi.embed($reportContainer.get(0), embedConfiguration);

 var reportPages; 

  

report.on('dataSelected', function(event)

{

var data = event.detail;

         

         console.log(JSON.stringify(data, null, ' '));

         

});

 ;

 

}

</script>

<div  id="reportContainer"></div>

</html>

Browse Categories

...