Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

jonvitale
Contributor III

easy way to check if dimension has values

Hello all,

I'm revising a d3-based extension (Sankey) and I have a scenario in which I want to load several dimensions, but depending on the time in the year, several of these dimensions may have empty values. Specifically, I'll have dimensions like Q1, Q2, Q3, Q4 set up, but until its actually the 2nd quarter of the year (school year, actually), there won't be data there.

So, I can check if there are any non-null values by doing something like this with the layout object in the paint function:

var qData = layout.qHyperCube.qDataPages[0];

var nDim = layout.qHyperCube.qDimensionInfo.length;

var dimIsNull = [];

for (var d = 0; d < nDim; d++){

     var allNull = true;

     for (var r = 0; r < qData.qMatrix.length; r++){

          if (qData.qMatrix.qElemNumber >= 0){ // or I might check for a specific text like [.qText != "-"]

               allNull = false;

               break;

          }

     }

     dimIsNull = allNull;

}

              

    

This works, but it seems inefficient because I have to loop through the entire HyperCube on every paint call. Really, I would only need to call this function once on load. Also, since I come from the R programming world iterating through this sort of matrix pains me deeply. Is there a more elegant way to do this?

Thanks, Jonathan

1 Solution

Accepted Solutions
Highlighted
erik_wetterberg
Valued Contributor III

Re: easy way to check if dimension has values

Hi,

There is some info on diemnsions in the dimensionInfo array:

https://help.qlik.com/en-US/sense-developer/June2017/Subsystems/EngineAPI/Content/Structs/NxDimensio...

Is qCardinal what you are after? Use the dubugger to explore what is in the structure.

Doing this just on load seems not a good idea... What if the user makes a selection that excludes Q2, Q3, Q4? Or if he already has made such a selection when the extension first loads and then clears it?

Hope this helps

Erik Wetterberg

Erik Wetterberg
https://extendingqlik.upper88.com/
5 Replies
jesper_snihs
Contributor

Re: easy way to check if dimension has values

Hi Jonathan,

If you only want the code to run on load, can't you place the code inside the controller instead since the controller is only executed on load?

Regards

Jesper

Highlighted
erik_wetterberg
Valued Contributor III

Re: easy way to check if dimension has values

Hi,

There is some info on diemnsions in the dimensionInfo array:

https://help.qlik.com/en-US/sense-developer/June2017/Subsystems/EngineAPI/Content/Structs/NxDimensio...

Is qCardinal what you are after? Use the dubugger to explore what is in the structure.

Doing this just on load seems not a good idea... What if the user makes a selection that excludes Q2, Q3, Q4? Or if he already has made such a selection when the extension first loads and then clears it?

Hope this helps

Erik Wetterberg

Erik Wetterberg
https://extendingqlik.upper88.com/
jonvitale
Contributor III

Re: easy way to check if dimension has values

As Erik mentions, it's probably a bad idea for me to put the code outside the paint function - unforeseen circumstances.

But, I am interested in what you mean by the "controller". I'm not using angular here.

Jonathan

jonvitale
Contributor III

Re: easy way to check if dimension has values

You've done it again Erik! There it is right in the hyperCube. Dimension index 3, qCardinal is 0.

Capture.PNG

Thanks again.

jesper_snihs
Contributor

Re: easy way to check if dimension has values

Yes, I'm referring to the controller in angular. So if you don't use that you can ignore my previous answer.