Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PBCIT
Frequent Visitor

Export to Excel past 150,000 rows

Hello all,

 

Ok so I have a report where my users can use a variety of filters to get the exact data they need from a table. Problem is that when they export to excel, at times they hit the 150,000 row limit for the .xlxs file. I don't want them to use the analyze in excel feature because it undoes all of the filters they put in, not to mention the datasources I am pulling from won't make sense to them. I'm wanting them to be able to export from excel and not have to do a bunch of work after in order to get the information they are wanting. What sort of workarounds can I employ? Are there any kinds of Powershell scripting I can use? What about a button with an R or python script that would export the filtered data? Or something easier that maybe I am missing? Any ideas would be greatly appreciated

4 REPLIES 4
PMadan
Frequent Visitor

Hi,

 

1. Create an Index Column starting from 0

2. Add Column Export page No  where Export Page No = Number.RoundDown((IndexValue/ 150000), 0) +1 to create Export Page No 

3. Create a Powershell Script to export records by Export Page No.. You may refer the script below:

4. While I can get the records exported in chunks of 150,000... I noticed that export strangely failed when the size was set for anything more than. There are only 12-13 columns in the table ad it shouldn't ideally fail for this kind of table. I have added an additional check  

 

Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile
Import-Module ImportExcel

$password = "MyPassword" | ConvertTo-SecureString -asPlainText -Force
$username = "MyEmail@email.com"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)

$workspaceId = "WorkspaceIdThatcabBeSeenInUrl"
$datasetId = "DataSetIdOfPBIXReport"
$dateParameter = "2023-06-01"

$exportPageSize = 30000
$pageSize = 25

$sleepPeriodShort = 10
$sleepPeriod = 10
$sleepPeriodToExecRefresh =10800

<####################################################################################
                    Extract outputs and Write to XLSX Files
####################################################################################>
  Write-Host "START: Export to XLSX"  Get-Date -Format "yyyyMMdd HH:mm:ss"

  Connect-PowerBIServiceAccount -Credential $credential
 
  try {
       
        Write-Host "Started for "  $dateParameter

        $execRequestUrlCount = "datasets/" + $datasetId + "/executeQueries"
        $execRequestBodyCount = @"
    {
      "queries":
        [
            {"query": "
      EVALUATE SUMMARIZECOLUMNS(UA[Date], FILTER(UA, UA[Export Page No]=MAX(UA[Export Page No])), \"ExportPage\", MAX(UA[Export Page No]) )
           "
            }
        ],
        "serializerSettings": {"includeNulls": true}
    }
"@



        # Creating the Result Variable by passing through the DAX Query to the Power BI PowerShell Module
        $execResultCount = Invoke-PowerBIRestMethod -Method POST -Url  $execRequestUrlCount -Body $execRequestBodyCount

        #Write-Host "Completed for " $dateParameter
        #Write-Host $execResultCount


        # Take the results and convert it from JSON
        $parsedCount = $execResultCount | ConvertFrom-Json

        $outputDate = (($parsedCount.results[0].tables[0].rows[0][0]).PSObject.Properties | Select -First 1 ).Value
        $outputCount = (($parsedCount.results[0].tables[0].rows[0][0]).PSObject.Properties | Select -Last 1 ).Value

        Write-Host $outputDate  $outputCount

        if ($outputCount -gt 0) {

          for ($i = 1; $i -le $outputCount; $i++) {
            $filePath = ".\OneDrive\SearchAPI\UA_" + $dateParameter + "_" + $i + ".xlsx"

            $execRequestUrl = "datasets/" + $datasetId + "/executeQueries"

            $execRequestBody = @"
    {
      "queries":
        [
            {"query": "EVALUATE FILTER(UA, UA[Export Page No]= $i)"
            }
        ],
        "serializerSettings": {"includeNulls": true}
    }
"@

            $execResult = Invoke-PowerBIRestMethod -Method POST -Url  $execRequestUrl -Body $execRequestBody

            Write-Host $i

            # Take the results and convert it from JSON
            $parsed = $execResult | ConvertFrom-Json

            # This is where I take the results and export it to XLSX
            $output = $parsed.results[0].tables[0].rows
            $output | Export-Excel -Path $filePath  

          }

        }
    }
    catch {
      Write-Host  $_.Exception.Message -foregroundColor red -backgroundColor yellow
    }

  Disconnect-PowerBIServiceAccount
}

Write-Host "END: Export to XLSX " Get-Date -Format "yyyyMMdd HH:mm:ss"
v-xicai
Community Support
Community Support

Hi @PBCIT ,

 

You can expand the option "Advanced options" to enter into SQL statement. 

Sql statement.png

You may type codes like below to get limited data rows. See more :SQL TOP, LIMIT or ROWNUM Clause.

 

SELECT TOP 1000 product_name, list_price FROM production.products ORDER BY list_price DESC;

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

GilbertQ
Super User
Super User

Hi there

That is the current limitation in the Power BI Service.

Why can they not use the Analyze in Excel option?
You can certainly use the Pivot tables to filter the data that you need (And Excel will remember the filters)
As well as formatting it into the format required?




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

@GilbertQ @v-xicai , the issue I have is that I need my end users to be able to export the table after they applied their filters in Power BI. The analysis in Excel is something I'm not sure would work because the data sources can be a little confusing to the end users in my company as they are not versed in database concepts and how everything is interconnected. The same would be the issue with the Advanced options Sql option. I'm looking for a way that my end users can do this. @GuyInACube do you have any ideas? I watch your videos all the time and I'm sure if there was something that could be done, you'd know it

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors