Forum Discussion
New API Endpoint with DAX Queries
- 4 years ago
I finally got this partially worked out with the help of one of the very helpful Power BI engineers. For some reason datasets in My Workspace don't seem to be getting proper build permissions, so I decided to switch to just testing datasets in my v2 workspaces.
I initally thought that I had to use the format https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId} because that is what I'm accustomed to doing. This will probably change as this gets closer to GA, but for now you actually just remove the parts about the group and reference the dataset directly. For example: https://api.powerbi.com/v1.0/myorg/datasets/f388a618-2c93-41c5-8528-44c0c1129d70/executeQueries
Once I made that change, I was able to return data from a Powershell script and Postman. Still not sure about the permssions in My Workspace, but I'll likely never use that anway.
One thing I noticed is that you didn't escape your double quotes in query. In the blog post they Kay mentions and don’t forget to escape quotation marks with a backslash (\”). The latest query that I copy and pasted from Power BI Desktop looked like this:
DEFINE
VAR __DS0Core =
SUMMARIZECOLUMNS(
'Proposals'[DOCUMENT_ID],
\"SumDOCUMENT_DIRECT_AMT\", CALCULATE(SUM('Proposals'[DOCUMENT_DIRECT_AMT]))
)
VAR __DS0PrimaryWindowed =
TOPN(501, __DS0Core, 'Proposals'[DOCUMENT_ID], 1)
EVALUATE
__DS0PrimaryWindowed
ORDER BY
'Proposals'[DOCUMENT_ID]
Hope that helps.
Same error 😥 Would you be able to post your $requestBody?
$requestBody = @"
{“queries”: [{“query”:”EVALUATE SUMMARIZE('Calendar','Calendar'[Year],\"Days in year\",COUNT('Calendar'[Date]))“}], “serializerSettings”:{“incudeNulls”: true}}
"@
- rjhale4 years agoHelper V
The last query that I posted was actually from a Power Automate variable that I was working with. I also tested a different query using Powershell, and here is an example of the $requestBody variable:
$requestBody = @" { "queries": [ { "query": " DEFINE VAR __DS0FilterTable = TREATAS({\"CHEM\"}, 'Proposals'[DOCUMENT_DEPT_NAME]) VAR __DS0Core = SUMMARIZECOLUMNS( 'Proposals'[DOCUMENT_ID], __DS0FilterTable, \"SumDIRECT_AMT\", CALCULATE(SUM('Proposals'[DIRECT_AMT])) ) VAR __DS0PrimaryWindowed = TOPN(501, __DS0Core, 'Proposals'[ID], 1) EVALUATE __DS0PrimaryWindowed ORDER BY 'Proposals'[ID]" } ] } "@@I would also make sure that your double quotes are the correct type of double quotes. I'm not sure if you copy and pasted right from your PS script, but it looks to me like you have two different types of double quotes being used.
- Anonymous4 years agoNot applicable
And jhayes0128. I also noted that in your code, you are not only using straight quotes (sorry for the probably not fully correct term). You should use " and not “ or ”.
Here is my simple request body:# Here comes the DAX query wrapped in the request body. # Using @" "@ makes the text literal, which is much easier # Not that " in the DAX query must be preceeded by a \ # Port Calls Query - List ship count per country code $requestBody = @" { "queries": [ {"query": "EVALUATE SUMMARIZECOLUMNS( 'Movements'[countryCode], \"Ship Count\", [shipCount] )" } ], "serializerSettings":{"incudeNulls": true}} "@- jhayes01284 years agoFrequent Visitor
You are my hero Anonymous !!!! IT WORKS!
I never would've guessed this fix. thank you thank you thank you!!!