Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How do you get a measures expression from Hypercube? and is it possible to change it?

Hi,

I'm new to extension and Javascript in general. Have started poking around and experimenting with extensions.

I am wondering if it's possible to retrieve the expression of a measure and change it.

And if it's possible how, where and when should you do it.

Best regards

Karl

1 Solution

Accepted Solutions
ErikWetterberg

Hi Karl,

You could check out this thread.

When you do getProperties() in an extension with a qHyperCubeDef you will get a structure thats described here. The measure will be in qMeasures[index].qDef. Modify it and call setProperties:

var me = this;

this.backendApi.getProperties().then(function(reply){

reply.qHyperCubeDef.qMeasures[0].qDef.qDef = '1+1'; //your new expression

me.backendApi.setProperties(reply);

});

Note that both setProperties and getProperties are asynchronous calls.

Erik

edit: added the trailing );

edit2: added another qDef..

View solution in original post

15 Replies
yblake
Partner - Creator II
Partner - Creator II

All measures informations come in : layout.qHyperCube.qMeasureInfo

The Backend API GetMeasureInfos will also return measures informations.

https://help.qlik.com/sense/en-US/developer/#../Subsystems/Workbench/Content/BuildingExtensions/API/...

Modifying an expression syntax will require use of Mashup API, a good starting point is the createCube method :

https://help.qlik.com/sense/en-US/developer/#../Subsystems/Workbench/Content/BuildingWebsites/API/Me...

ErikWetterberg

Hi Karl,

You could check out this thread.

When you do getProperties() in an extension with a qHyperCubeDef you will get a structure thats described here. The measure will be in qMeasures[index].qDef. Modify it and call setProperties:

var me = this;

this.backendApi.getProperties().then(function(reply){

reply.qHyperCubeDef.qMeasures[0].qDef.qDef = '1+1'; //your new expression

me.backendApi.setProperties(reply);

});

Note that both setProperties and getProperties are asynchronous calls.

Erik

edit: added the trailing );

edit2: added another qDef..

Not applicable
Author

Thanks Erik!

There where a type-o in your answer code, so for future readers could you add ); to the end of the codesnippet?

ErikWetterberg

OK, fixed. Thanks for pointing that out.

/Erik

Not applicable
Author

Found one more thing, there where a qDef missing also. Got a JSON Parse error

  1. reply.qHyperCubeDef.qMeasures[0].qDef.qDef = '1+1'; //your new expression 
Not applicable
Author

I have one more question, is there a notification when the properties in a hypercube changes?

What I am trying to do is add a set analsysis to a measure and only wan't to do that once every time the user changes/adds a measure.

Not applicable
Author

You will get a change notification in the form of a call to the paint method on all invalidations of the object. changing properties are one action that will invalidate for you. reload of data and change of related selections are other.

Not applicable
Author

My Javascript knowledge is very limited. I don't understand what you mean, could you explain with a code snippet?

Not applicable
Author

define( [

],

function ( ) {

  return {

  paint: function () {

  // This segment will be called every time

  // the visualization needs to handle the

  // change induced by an invalidation

  }

  };

} );