0
Help us understand the problem. What are the problem?

posted at

updated at

Power BI workout - Rebind Report In Group

Power BI レポートのコピー操作ではない。Power BI レポートにバインドされているデータセットを再バインドする。
たとえば、サブセットのデータセットで作成したレポートをPower BI サービス 上ででの操作(Power BI REST API)で本来のデータセットにバインドする。

Power BI Cmdlets for Windows PowerShell and PowerShell Core

Power BI REST API

Reports - Rebind Report In Group

Rebinds the specified report from the specified workspace to the specified dataset.

If the specified dataset resides in a different new workspace experience workspace from the report or in My workspace, then a shared dataset will be created in the report's workspace.
On rebind, reports with a live connection will lose that connection and instead have a direct binding to the target dataset.

Permissions

  • Write permission on the specified report.
  • Build permission on the target dataset.

ワークスペースの Member ロールで充分

Required Scope

Report.ReadWrite.All

POST https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/Rebind

URI Parameters

Name In Required Type Description
groupId path True string uuid The workspace ID
reportId path True string uuid The report ID

Request Body

Name Required Type Description
datasetId True string The new dataset for the rebound report. If the dataset resides in a different workspace than the report, a shared dataset will be created in the report's workspace.

Responses

Name Type Description
200 OK OK

DEMO | Rebind Power BI report

動作を確認する程度で
DEMO2 (Power BI ワークスペース)に配置された Report2 (Power BI レポート)を Dataset1 (Power BI データセット)にバインドする。

Define

# Report in workspace
$WorkspaceName_report = "DEMO2"
$ReportName = "Report2"

# Dataset in workspace
$WorkspaceName_dataset = $null
$DatasetName = "Dataset1"

Login Power BI

Login-PowerBI | Out-Null

Get Power BI workspace | Get Power BI report | Get Power BI dataset

$Workspace = Get-PowerBIWorkspace -Name $WorkspaceName_report
$Report = Get-PowerBIReport -Workspace $Workspace -Name $ReportName

if (
    $WorkspaceName_dataset -eq $WorkspaceName_report -or 
        $null -eq $WorkspaceName_dataset
) {
    $Dataset = Get-PowerBIDataset -Workspace $Workspace
        | Where-Object Name -EQ $DatasetName
} else {
    $Dataset = Get-PowerBIDataset `
        -Workspace (Get-PowerBIWorkspace -Name $WorkspaceName_dataset)
        | Where-Object Name -EQ $DatasetName
}

Invoke Power BI REST API

$Url = "groups/$($Workspace.Id)/reports/$($Report.Id)/rebind"
$Body = @"
{"datasetId": "$($Dataset.Id)"}
"@

Invoke-PowerBIRestMethod -Method Post -Url $Url -Body $Body

Logout Power BI

Logout-PowerBI

思ったこと🙄

Power BI コマンドレットを使うのは サービスへのログインが簡単だし、用意されていないコマンドレットは Invoke-PowerBIRestMethod で対応できるから。完全な自動化が必要がないのであればスクリプト用意して適宜で使えばいいよね。

その他

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
0
Help us understand the problem. What are the problem?