Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
sheldonqlik
Contributor II
Contributor II

Qliksense custom measure property for extension with expression value

I have created a custom property for a measure in my extension

CustomMeasureProp:{

          type:"string",

          label:"Custom Measure Property",

          ref:"customMeasureProperty",

          expression: "optional"

}

In the QlikSense Desktop I am able to add my extension and see the custom property when adding my measure.

I populate it with my EXPRESSION Max(value).

THE QUESTION.  

How do I access that evaluated expression through the api?

I have used my code

$scope.backendApi.getProperties().then(function(reply){

          angular.forEach(reply.qHyperCubeDef.qMeasures,function(measure){

           console.log('MEASURE',measure);

           if(typeof measure.customMeasureProperty!=='undefined'){

              console.log('MEASURE LABEL', measure.customMeasureProperty);

         }

});

Rather than returning the evaluated expression when looking  at the object measure.customMeasureProperty, it returns the string Max(value).

So how do get the evaluated value?

27 Replies
pablolabbe
Luminary Alumni
Luminary Alumni

Hi Sheldon,

  Did you solved this issue ?

yblake
Partner - Creator II
Partner - Creator II

I found this trick to get it working...

InformationLabelProp: {

  type  : 'string',

  component: 'expression',

  label : 'Evaluates for each row',

  ref  : 'qAttributeExpressions.0.qExpression',

  defaultValue: ''

},


You may check.

Regards

Not applicable

Hello Alexander,

Do you know how to specify an expression which would return a meaningful color value in a custom extension?

I'm following steps you've done (case with expression evaluated per each row) and I'm getting qAttrExps, but their values are numbers, not strings, and for instance instead of RGB(0,0,0) I receive value '4278190080'.

My expression is defined like this - IF($(fieldName)<0,RGB(0,0,0)). For rows which are falsy for IF statement I end up with 'NaN'.

Thanks in advance

Not applicable

Hi Alexander,

According to the documentation, same approach can be applied for Dimensions. Only difference is that for dimensions the property is named qAttributeExpression instead of qAttributeExpressions (no 's' at the end).

The thing is that as a result, I can't see qAttrExps created. Even in qDimensionInfos qAttrExpInfo is empty for every dimension. Can you please assist?

Cheers,
Adrian

pamaxeed
Partner - Creator III
Partner - Creator III

Hi,

i also was wondering if for the Dimensions we have the same Attribute, qAttrExps.

Somebody could go further regarding this topic?

I would like to define custom attribute on dimension level, so it could be nice if somebody could assist.
The documentation says that there exists such property:

qAttributeExpression

List of attribute expressions.

Array of NxAttrExprDef

thanks!

guantujiang
Contributor III
Contributor III

then how can we do the same work in dimension?  I try in the cub and it work, but the expression can not be evaluation

code:

dimensions: {

 

  columnWidth: {

  type  : 'string',

  component: 'expression',

  label : 'Column Width',

  ref  : 'qDef.columnWidth',

  defaultValue: ''

  },

  },

simondachstr
Luminary Alumni
Luminary Alumni

Actually that's expected as rgb() is interpreted as a number by the engine. Simply replace with strings.

jonvitale
Creator III
Creator III

This is old,

But I notice that you do not use an "=" sign in front of the evaluate for each row expression. I am noticing that in my work reproducing this, when I use an equal sign the expression is not evaluated. When I write an expression without the leading =, then I'm okay. I'm worried that this will be confusing for users.

I am setting expression to "optional" but have also tried "always"

robcastle
Partner - Contributor
Partner - Contributor

Can someone help me understand this solution?

I'm trying to add a property (expression) to a dimension that I want to use to define a color based on the value of the cell.

I defined my property like this:

var style={

ref: "qAttributeExpressions.0.nwsStyle",

label: "Style",

type: "string",

//expression: "always",

component: "expression"

};

And I'm accessing this expression in my extension code like this.

style = dimensionInfo[key].qAttrExprInfo[0].nwsStyle;

What gets returned is the expression formula and not the evaluated expression.. 

Returned results:

If(LEVEL = 1, 'background-color:green;',

If(LEVEL = 2, 'background-color:lightgreen;',

If(LEVEL = 3, 'background-color:yellow;',

If(LEVEL = 4, 'background-color:lightred;',

If(LEVEL = 5, 'background-color:red;','background-color:gray;')))))

I'm expecting the style to be returned so I can apply it to the html.

Does anyone know how to make this work? I noticed several people trying to do this in the forums but I'm not finding a successful solution.

jonvitale
Creator III
Creator III

Hi Rob, I think I got what you are looking for working. I modified an extension to give some color-by-expression features. Let's see what we can do:

First, in my dimension, where I want to color by expression, I use the ref "qAttributeExpressions.0.qExpression" and not a custom reference name, like your "qAttributeExpressions.0.nwsStyle". I'm not sure that this matters 100%, but I think it tells Qlik to evaluate this expression for each dimensional value and put the result with the rest of the data.


Next, in the body of my code (the paint function), I can find the values deep in my layout object:


Capture.PNG

Basically, in my case, I have a matrix with 16 rows, representing 16 combinations of the the two dimensions I'm using in my object. The array[3] is because I have 2 defined dimensions and 1 measure. If I dive into the first dimension I see the object qAttrExps and a sub-object qValues. Because I used qAttributeExpressions.0.qExpression (with a zero) I get my evaluated color expression in the first index of the qValues array. Depending on how you set this up it could either by a Num or a Text. In my case the expression returned a text, a nice RGB representation.


Give that a try and let me know if it works. I did this a couple months ago, so I'm a little rusty on what I've done. But hopefully this helps. Also, if you want to see my code where I did this stuff you can go here:


GitHub - jonvitale/SenseColorableSankey: Qlik Sense Colorable Sankey Extension