Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

iliasmansouri
New Contributor II

Create hypercube for visualization in Qlik Engine Api

Hello all,

Following this post: Add attribute expressions to a measure ‒ Qlik Sense Developers I'm trying to construct my own hypercube using the Sales Discovery app within the Qlik Engine API. I made a similar hypercube defIned like this:

{

     "jsonrpc": "2.0",

     "id": 11,

     "method": "CreateSessionObject",

     "handle": 1,

     "params": [

          {

               "qInfo": {

                    "qId": "",

                    "qType": "Chart"

          },

          "qHyperCubeDef": {

               "qStateName": "$",

               "qDimensions": [

                    {

                         "qLibraryId": "",

                         "qNullSuppression": false,

                         "qIncludeElemValue": false,

                         "qDef": {

                              "qGrouping": "N",

                              "qFieldDefs": [

                              "Region"

                         ],

                         "qFieldLabels": [

                              ""

                         ],

                         "qSortCriterias": [

                              {

                                   "qSortByState": 0,

                                   "qSortByFrequency": 0,

                                   "qSortByNumeric": 0,

                                   "qSortByAscii": 0,

                                   "qSortByLoadOrder": 1,

                                   "qSortByExpression": 0,

                                   "qExpression": {

                                        "qv": ""

                                   }

                              },

                              {

                                   "qSortByState": 0,

                                   "qSortByFrequency": 0,

                                   "qSortByNumeric": 0,

                                   "qSortByAscii": 0,

                                   "qSortByLoadOrder": 1,

                                   "qSortByExpression": 0,

                                   "qExpression": {

                                        "qv": ""

                                   }

                                }

                              ]

                           }

                         }

                    ],

                    "qMeasures": [

                         {

                              "qLibraryId": "",

                              "qSortBy": {

                              "qSortByState": 0,

                              "qSortByFrequency": 0,

                              "qSortByNumeric": 0,

                              "qSortByAscii": 0,

                              "qSortByLoadOrder": 1,

                              "qSortByExpression": 0,

                              "qExpression": {

                                    "qv": ""

                               }

                           },

                           "qDef": {

                              "qLabel": "Chart HC Properties measures label",

                              "qDescription": "Chart HC Properties measure description",

                              "qTags": [

                                   "tags"

                              ],

                              "qGrouping": "N",

                              "qDef": "Count(Sales)"

                         },

                         "qAttributeExpressions": [

                              {

                                   "qExpression": "Max(Sales)"

                              },

                              {

                                   "qExpression": "'Mini:' & Min(Sales)"

                         }

                   ]

               }

           ]

       }

     }

   ]

}

Afterwards I try to aquire the Data with GetHypercubeData:

{

      "handle": 4,

      "method": "GetHyperCubeData",

      "params": {

      "qPath": "/qHyperCubeDef",

      "qPages": [

           {}

           ]

      }

}

Finally, this is the response that I get:

{    

     "jsonrpc": "2.0",

     "id": 14,

     "result": {

          "qDataPages": [

               {

                    "qMatrix": [],

                    "qTails": [],

                    "qArea": {

                         "qLeft": 0,

                         "qTop": 0,

                         "qWidth": 0,

                         "qHeight": 0

                    }

             }

          ]

      }

}

Can someone show me how to correctly build a cube and extract the data with Qlik Engine API using preferably the Customer Sales example? Due to restrictions, this should be implemented using JSON's so no other methods are allowed.

Thanks in advance!

1 Solution

Accepted Solutions
Employee
Employee

Re: Create hypercube for visualization in Qlik Engine Api

Oh, I think I know what the problem is. You are not doing a reference to fields and measures, but you are trying to reference predefined master dimensions and measures. In that case you shouldn't use the "qDef" property. You should instead use the "qLibraryId" property to refer to the ID of the relevant master measure/dimension. Check out this page: Creating dimensions ‒ Qlik Sense Developers In particular, have a look at the (tiny) section titled "Referencing predefined dimensions" here Creating dimensions ‒ Qlik Sense Developers.

And by the way, that tool I pointed to earlier is very useful for looking up ID's as well.

8 Replies
Employee
Employee

Re: Create hypercube for visualization in Qlik Engine Api

You're passing an empty page to the "GetHyperCubeData" call. Try doing something like this:

{

  "handle": 4, 

  "method": "GetHyperCubeData", 

  "params": { 

  "qPath": "/qHyperCubeDef", 

  "qPages": [ 

      { "qTop": 0, "qLeft": 0, "qHeight": 10, "qWidth": 2 }

    ] 

  } 

}

You might also want to look into this page:

Get the values of a chart, a table or a scatter plot ‒ Qlik Sense Developers

iliasmansouri
New Contributor II

Re: Create hypercube for visualization in Qlik Engine Api

Yes indeed, I just figured it out also but I get NaN's for the attribute expressions field. It isn't possible to use the measure names? Here an exerpt of the result that I get

{

     "qText": "Hetrick Systems",

     "qNum": "NaN",

     "qElemNumber": 0,

     "qState": "O"

},

{

     "qText": "0",

     "qNum": 0,

     "qElemNumber": 0,

     "qState": "L",

     "qAttrExps": {

          "qValues": [

          {

               "qNum": "NaN"

          },

          {

               "qText": "Mini:",

               "qNum": "NaN"

          }

     ]

}

Employee
Employee

Re: Create hypercube for visualization in Qlik Engine Api

Is this a result from the hypercube defined above? In that case it seems like "Count(Sales)" returns 0 for the "Region" value "Hetrick Systems". There are no sales entries for that region, then I guess it makes sense for "Max(Sales)" and "Min(Sales)" to return NaN.

iliasmansouri
New Contributor II

Re: Create hypercube for visualization in Qlik Engine Api

I see. But when changing the dimension to Customer and trying to visualise the amount of sales per Customer I get a list of the Customers but still NaNs for the Sales. So if I'd like to make a simple bar chart which represents the amount of sales for every customer, how should I proceed to define the hypercube? Thanks in advance

Employee
Employee

Re: Create hypercube for visualization in Qlik Engine Api

Are you sure you have the field name right? If it is the "Sales Discovery" app you find at Qlik Sense your are using, then I believe the field named ought to be "Sales Amount", not just "Sales".

By the way, this tool can be useful for exploring object definitions when developing:

Qlik Explorer for Developers is here!

iliasmansouri
New Contributor II

Re: Create hypercube for visualization in Qlik Engine Api

Indeed, Sales is defined as the sum of the Sales Amount but I already tried with Sales Amount and I also get NaNs. I appreciate the effort of helping, thank you.

Employee
Employee

Re: Create hypercube for visualization in Qlik Engine Api

Oh, I think I know what the problem is. You are not doing a reference to fields and measures, but you are trying to reference predefined master dimensions and measures. In that case you shouldn't use the "qDef" property. You should instead use the "qLibraryId" property to refer to the ID of the relevant master measure/dimension. Check out this page: Creating dimensions ‒ Qlik Sense Developers In particular, have a look at the (tiny) section titled "Referencing predefined dimensions" here Creating dimensions ‒ Qlik Sense Developers.

And by the way, that tool I pointed to earlier is very useful for looking up ID's as well.

iliasmansouri
New Contributor II

Re: Create hypercube for visualization in Qlik Engine Api

Thank you very much for your assistance, finally figured it all out.

Community Browser