最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Power Bi export API filtered is not working - Stack Overflow

programmeradmin6浏览0评论

my report

my code :

export_url = f".0/my/groups/{workspace_id}/reports/{report_id}/ExportTo"
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}
payload = {
    "format": "pdf",
    "powerBIReportConfiguration": {
        "reportLevelFilters": [
            {
                "filter": "EXT_SYS_CODE in ('XNET', 'TW')"
            }
        ]
    }
}
export_response = requests.post(export_url, headers=headers, json=payload)

reportLevelFilters does not work. The downloaded report still contains other EXT_SYS_CODE data. Please tell me possible reasons.

It is expected that report level filtering can be used.

my report

my code :

export_url = f"https://api.powerbi/v1.0/my/groups/{workspace_id}/reports/{report_id}/ExportTo"
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}
payload = {
    "format": "pdf",
    "powerBIReportConfiguration": {
        "reportLevelFilters": [
            {
                "filter": "EXT_SYS_CODE in ('XNET', 'TW')"
            }
        ]
    }
}
export_response = requests.post(export_url, headers=headers, json=payload)

reportLevelFilters does not work. The downloaded report still contains other EXT_SYS_CODE data. Please tell me possible reasons.

It is expected that report level filtering can be used.

Share Improve this question asked Mar 31 at 4:50 HRUGDHRUGD 1 New contributor HRUGD is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1
  • Are you using import mode, direct query or live connection? – Pratik Lad Commented Mar 31 at 11:07
Add a comment  | 

1 Answer 1

Reset to default 0

Troubleshooting reasons for API filter failure:

  1. Report-level filtering in the Export API works only if the report uses Import Mode or DirectQuery. It does not work with Live Connection.

  2. Use datasetFilters instead of reportLevelFilters, if report is based on "Live Connection/Direct Query":

payload = {
    "format": "PDF", 
    "datasetFilters": [  # Using datasetFilters instead of reportLevelFilters
        {
            "filter": "TableName/EXT_SYS_CODE in ('XNET','TW')" 
        }
    ]
}
  1. Include Table name in your Filter format, so, the updated format will be:
import requests

export_url = f"https://api.powerbi/v1.0/my/groups/{workspace_id}/reports/{report_id}/ExportTo"
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}

payload = {
    "format": "pdf",
    "powerBIReportConfiguration": {
        "reportLevelFilters": [
            {
                "filter": "TableName/EXT_SYS_CODE in ('XNET','TW')"  
            }
        ]
    }
}

export_response = requests.post(export_url, headers=headers, json=payload)
  1. If multi-value filtering (in ('XNET','TW')) does not work, try testing a single value first:

"filter": "Tablename/EXT_SYS_CODE eq 'XNET'"

  1. If your report has a Parameter for EXT_SYS_CODE, use this instead of filters:
"powerBIReportConfiguration": {
    "parameters": [
        {
            "name": "EXT_SYS_CODE",
            "values": ["XNET","TW"]
        }
    ]
}
  • Check the attached Microsoft documentation for more information regarding Filtering a report:

Filter a report using query string parameters in the URL - Power BI | Microsoft Learn

发布评论

评论列表(0)

  1. 暂无评论