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

QlikSense [2.1.1] Working with multiple HyperCubes

Hello,

I need to create an extension with 2 levels of data:

- 1 level with data aggregated by Dimension1

- 1 level with data aggregated by Dimension2, for EACH Dimension1

Let's say I have Dimension1 = Country and Dimension2 = City

I would like to

- measure Average Age ( avg(Age) ) by Country and place on a map each Country with a color-coding related to the Average Age of this Country

- when I click on a Country, no filter is applied on the model but I can see in a simple table : Average Age ( avg(Age) ) by City of the selected Country

Of course I don't want to do dumb maths like calculating the average City average Age of each Country. I could do something more clever but it's not the point here.

So how could I do 2 Hypercubes :

- 1 for Average Age by Country

- 1 for Average Age by Country and City

?

I can create 2 HyperCubes in the initialProperties of my extension but I find only 1 in the layout object of the paint function so I guess that's not the way to do it.

I have tried to create an HyperCubeDef inside the paint function too, but i can't retrieve data.

Thanks a lot for your feedbacks, ideas, suggestions, advices.

6 Replies
nstefaniuk
Creator III
Creator III
Author

Ok 1 solution found:

Start like that:

define( ['//code.jquery.com/ui/1.11.4/jquery-ui.js','js/qlik'],

    function ( jqueryui, qlik ) {

        'use strict';

in paint:

paint: function ( $element, layout ) {

  var app = qlik.currApp(this);

Define HyperCube:

var qHyperCubeDef2 = {

  qDimensions : [

                        { qDef : {qFieldDefs : ["Place"]}}, { qDef : {qFieldDefs : ["Result"]}}

                    ],

  qMeasures : [

                        { qDef : {qDef : "count(distinct Fact_Id)", qLabel :"Nb Cases"}}

                    ],

  qInitialDataFetch: [

  {

  qWidth: 10,

  qHeight: 100

  }

  ]

  };

Create hypercube using Qlik.CreateCube:

  app.createCube(qHyperCubeDef2, function(reply) {

  console.log('Second HyperCube :', reply.qHyperCube);

});

Put your code inside function reply. I guess it's asynchronous (you can tell when your data will be ready) so you have to build your rendering code inside this function.

It seems it's possible to put more than 1 HyperCube in initialproperties. I have successfully do this but I don't understand how I can access to this second HyperCube in paint. "layout" contains only 1 HyperCube.

Thanks

Stefan_Walther
Employee
Employee

nstefaniuk
Creator III
Creator III
Author

Thanks but your example is far beyond my understanding : it seems you don't need paint() function and I don't event understand your 2-lines HTML. Anyway I will take the time to look at your examples to try to learn thinks.

Thanks

reddy-s
Master II
Master II

Hi ,

I think you have made the requirement a little complicated.

Can't you achieve this using a drill down dimmension?

Using this you will be able to achieve what you are looking for very easily.

nstefaniuk
Creator III
Creator III
Author

Mhmmm it's a pretty good idea indeed. I don't know how to define a pivot table hypercube and browse it with javascript but if I can find out how to do that, it will solve this issue with elegance.

Do you have some pointers on how to define a pivot table hypercube ? Thanks

reddy-s
Master II
Master II

Hi nstefaniuk,

You do not have to do any thing new here. When the visualization first render with the first level of drill, the hyper cube is only going to give you the first level. For example  lets consider there are 2 levels A and B. So when you use the drill down dimension in your visual, the hypercube is going to aggregate the measures for level A and when you happen to make a selection and drill down, the hyper cube is recreated with all the distinct values in level B and aggregate the measures accordingly.

Regards,

Sangram Reddy.