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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jhayes0128
Frequent Visitor

DAX REST API - NullArray

My powershell code:

$requestUrl = "datasets/291666dc-09a2-44e3-ba8b-24b590fd9331/executeQueries"

$requestBody = @"
{ “queries”: [{“query”:”EVALUATE SUMMARIZE('Calendar','Calendar'[Year],"Days in year",COUNT('Calendar'[Date]))“}], “serializerSettings”:{“incudeNulls”: true}}
"@

Login-PowerBI
$result = Invoke-PowerBIRestMethod -Method Post -Url $requestUrl -Body $requestBody
$parsed = $result | ConvertFrom-Json
$parsed.results[0].tables[0].rows | Format-List

 

Error:

Invoke-PowerBIRestMethod : One or more errors occurred.
At J:\test.ps1:35 char:11
+ $result = Invoke-PowerBIRestMethod -Method Post -Url $requestUrl -Bod ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod

Cannot index into a null array.
At J:\test.ps1:38 char:1
+ $parsed.results[0].tables[0].rows | Format-List
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

The error suggests that the DAX is wrong, but it's copy/pasted from the source .pbix file where it works fine.

jhayes0128_0-1630431969062.png

 

I have tried these variations of the $requestUrl:

$requestUrl = "datasets/291666dc-09a2-44e3-ba8b-24b590fd9331/executeQueries"
$requestUrl = "https://api.powerbi.com/v1.0/myorg/datasets/291666dc-09a2-44e3-ba8b-24b590fd9331/executeQueries"
$requestUrl = "291666dc-09a2-44e3-ba8b-24b590fd9331/executeQueries"

And these variations of $requestBody:

EVALUATE SUMMARIZE('Calendar','Calendar'[Year],"Days in year",COUNT('Calendar'[Date]))
EVALUATE SUMMARIZE('Calendar','Calendar'[Year],\"Days in year\",COUNT('Calendar'[Date]))   add \ to "Days in year"
EVALUATE SUMMARIZE(Calendar,Calendar[Year],\"Days in year\",COUNT(Calendar[Date]))     remove ' from tablename and add \

 

I have verified that 'Allow XMLA endpoints' and API permissions are granted. Please help!

 

Microsoft Example: https://powerbi.microsoft.com/en-us/blog/announcing-the-public-preview-of-power-bi-rest-api-support-...

Related thread:https://community.powerbi.com/t5/Developer/New-API-Endpoint-with-DAX-Queries/m-p/1998477

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jhayes0128 

Refer to this code, you can try table expression which looks like {\"Calendar\"}.

1.png

Try this code in your reuqest body: 

EVALUATE SUMMARIZE({\"Calendar\"},'Calendar'[Year],\"Days in year\",COUNT('Calendar'[Date]))

Based the related post, the end user solved his problems by using datasets in V2 workspace. You need build permission to use rest api for Dax Queries.

For reference:

2.png

Please check what kind of workspace is your dataset in. Test datasets in your V2 workspace instead of My Workspace or V1.

 

Best Regards,
Rico Zhou

 

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @jhayes0128 

Refer to this code, you can try table expression which looks like {\"Calendar\"}.

1.png

Try this code in your reuqest body: 

EVALUATE SUMMARIZE({\"Calendar\"},'Calendar'[Year],\"Days in year\",COUNT('Calendar'[Date]))

Based the related post, the end user solved his problems by using datasets in V2 workspace. You need build permission to use rest api for Dax Queries.

For reference:

2.png

Please check what kind of workspace is your dataset in. Test datasets in your V2 workspace instead of My Workspace or V1.

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.