Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
I am trying to write a Powershell script to create a partition in a Power BI dataset. Anyone know how to resolve this error? I am receiving the following error:
My Powershell Code:
$m_code = "let
Source = Sql.Database(`"source`", `"db`", [Query=`"sel column form table`", CommandTimeout=#duration(0, 1, 0, 0)])
in
Source"
$tmsl = "{
`"create`": {
`"parentObject`": {
`"database`": `"model name`",
`"table`": `"Table name`"
},
`"partition`": {
`"name`": `"test partition`",
`"source`": {
`"type`": `"m`",
`"expression`": [
`"$m_code`"
]
}
}
}
}"
invoke-ascmd -Server "powerbi://api.powerbi.com/v1.0/myorg/workspace" -Database "model Name" -Query $tmsl
Solved! Go to Solution.
Hi @poweruser1,
Perhaps you can take a look the following sample code if it help with your scenario:
$groupID = "<your group ID>"
$datasetID = "<your dataset ID>"
$token = Get-PowerBIAccessToken
$authHeader = @{ "Authorization" = "Bearer $token" }
$uri = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/datasets/$datasetID/Partitions"
$body = @{
"name" = "ImportName"
"mode" = "Import"
"source" = @{
"type" = "Query"
"query" = "SELECT * FROM $tableName"
"dataSource" = @{
"type" = "Sql"
"connectionDetails" = @{
"server" = "$serverName.database.windows.net"
"database" = "$databaseName"
"authentication" = "Windows"
}
}
}
}
$jsonBody = $body | ConvertTo-Json
Invoke-RestMethod -Uri $uri -Headers $authHeader -Method Post -Body $jsonBody
Regards,
Xiaoxin Sheng
Hi @poweruser1,
Perhaps you can take a look the following sample code if it help with your scenario:
$groupID = "<your group ID>"
$datasetID = "<your dataset ID>"
$token = Get-PowerBIAccessToken
$authHeader = @{ "Authorization" = "Bearer $token" }
$uri = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/datasets/$datasetID/Partitions"
$body = @{
"name" = "ImportName"
"mode" = "Import"
"source" = @{
"type" = "Query"
"query" = "SELECT * FROM $tableName"
"dataSource" = @{
"type" = "Sql"
"connectionDetails" = @{
"server" = "$serverName.database.windows.net"
"database" = "$databaseName"
"authentication" = "Windows"
}
}
}
}
$jsonBody = $body | ConvertTo-Json
Invoke-RestMethod -Uri $uri -Headers $authHeader -Method Post -Body $jsonBody
Regards,
Xiaoxin Sheng
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |