Forum Discussion

weiyu_chen's avatar
weiyu_chen
Frequent Visitor
4 years ago
Solved

What is the escape char for rest api execute queries in postman

POST Body:

{
"queries": [
{"query": "EVALUATE COUNTAX(FILTER('Activity',[Activity Status]=\"Completed\"), [Priority])"
}
],
"serializerSettings": {
"includeNulls": true
}
}
 
Got this error in Response:
{
"error": {
"statusCode": 0,
"errorCode": "QueryUserError",
"message": "Query (1, 1) The expression specified in the query is not a valid table expression.",
"errorDetails": [
{
"code": "AnalysisServicesErrorCode",
"detail": {
"type": 1,
"value": "3241803862"
}
}
]
}
}
 
Basically, this is my query: 
EVALUATE COUNTAX(FILTER('Activity',[Activity Status]="Completed"), [Priority])
How do I escape the '"' inside the body of the request. Is it '\', or something else? Thanks!
 
 

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi weiyu_chen ,

    I checked some of the relevant restrictions and it seems that none of them are touched on your side...

    1. Only 1 DAX query can be executed per REST API request.
    2. Each DAX query can have only 1 result set.
    3. Result sets are capped at 100k rows.
    4. Supported data types: string, numeric, boolean, blank, datetime and variant. Binary is not supported.
    5. Azure AS and SSAS do not support this DAX REST API.

    Is it possible that the error is reported because this DAX Query returned a single value, but the required return result here is a table? Change the DAX Query to the following form and see if it works:

    {
    "query": "EVALUATE SUMMARIZE (
        'Activity',
        \"countofpriority\", COUNTAX ( FILTER ( 'Activity', [Activity Status] = \"Completed\" ), [Priority] )
    )"
    }

    Best Regards

9 Replies

  • You can try

     

    "query""EVALUATE COUNTAX(FILTER('Activity',[Activity Status]=""Completed""), [Priority])"

    • weiyu_chen's avatar
      weiyu_chen
      Frequent Visitor

      lbendlin 

      Also tried: 

      "query": "EVALUATE COUNTAX(FILTER('Activity',[Activity Status]='"'Completed'"'), [Priority])"
      get the error:
      {
      "error": {
      "code": "BadRequest",
      "message": "Bad Request",
      "details": [
      {
      "message": "After parsing a value an unexpected character was encountered: '. Path 'queries[0].query', line 3, position 70.",
      "target": "request.queries[0].query"
      },
      {
      "message": "'request' is a required parameter",
      "target": "request"
      }
      ]
      }
      }
      Thanks!
      Weiyu
      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        Can you confirm that your original query runs in DAX Studio?

  • weiyu_chen's avatar
    weiyu_chen
    Frequent Visitor

    lbendlin 

    Thanks for the reply. I have tried your suggestion, get the following error:

    {
    "error": {
    "code": "BadRequest",
    "message": "Bad Request",
    "details": [
    {
    "message": "After parsing a value an unexpected character was encountered: \". Path 'queries[0].query', line 3, position 69.",
    "target": "request.queries[0].query"
    },
    {
    "message": "'request' is a required parameter",
    "target": "request"
    }
    ]
    }
    }
     
    The query body is:
    {
    "queries": [
    {"query": "EVALUATE COUNTAX(FILTER('Activity',[Activity Status]=""Completed""), [Priority])"
    }
    ],
    "serializerSettings": {
    "includeNulls": true
    }
    }
     
    Thanks!
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi weiyu_chen ,

    According to this official blog, its escape character is a backslash (\”). So I think your initial writeup should be correct...


    weiyu_chen wrote:

    POST Body:

    {
    "queries": [
    {"query": "EVALUATE COUNTAX(FILTER('Activity',[Activity Status]=\"Completed\"), [Priority])"
    }
    ],
    ....

    Please check if you enable Allow XMLA endpoints and Analyze in Excel with on-premises datasets under the tenant-level setting tab in the Power BI admin portal. Besides that, you need the Build permission for the dataset if you want to query by using this new REST API.

    Best Regards

    • weiyu_chen's avatar
      weiyu_chen
      Frequent Visitor

      Anonymous Thanks for the reply. Yes, I have enabled XMLA:

      Also I am the owner of the dataset. I can access it. The problem is within FILTER function, I have this issue. But in the following query in SUMMERIZE function, it's OK:

      {
      "queries": [
      {"query": "EVALUATE SUMMARIZE(Account, Account[Owner], \"Total\", SUM(Account[Annual Revenue]))"
      }
      ],
      "serializerSettings": {
      "includeNulls": true
      }
      }
      This query runs fine and return correct resultset.
      Thanks!
      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi weiyu_chen ,

        I checked some of the relevant restrictions and it seems that none of them are touched on your side...

        1. Only 1 DAX query can be executed per REST API request.
        2. Each DAX query can have only 1 result set.
        3. Result sets are capped at 100k rows.
        4. Supported data types: string, numeric, boolean, blank, datetime and variant. Binary is not supported.
        5. Azure AS and SSAS do not support this DAX REST API.

        Is it possible that the error is reported because this DAX Query returned a single value, but the required return result here is a table? Change the DAX Query to the following form and see if it works:

        {
        "query": "EVALUATE SUMMARIZE (
            'Activity',
            \"countofpriority\", COUNTAX ( FILTER ( 'Activity', [Activity Status] = \"Completed\" ), [Priority] )
        )"
        }

        Best Regards