Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
jonvitale
Creator III
Creator 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
ErikWetterberg

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

View solution in original post

5 Replies
_jespers_
Partner - Creator II
Partner - Creator II

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

ErikWetterberg

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

jonvitale
Creator III
Creator III
Author

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
Creator III
Creator III
Author

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

Capture.PNG

Thanks again.

_jespers_
Partner - Creator II
Partner - Creator II

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