Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

Highlighted
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
Honored Contributor

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

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..

Erik Wetterberg
Blog:https://extendingqlik.upper88.com/
Chrome extension:https://chrome.google.com/webstore/detail/add-sense/bbiljflfafkaejgdebbnmcohpidgkejj
15 Replies
Partner
Partner

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

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
Honored Contributor

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

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..

Erik Wetterberg
Blog:https://extendingqlik.upper88.com/
Chrome extension:https://chrome.google.com/webstore/detail/add-sense/bbiljflfafkaejgdebbnmcohpidgkejj
Not applicable

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

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
Honored Contributor

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

OK, fixed. Thanks for pointing that out.

/Erik

Erik Wetterberg
Blog:https://extendingqlik.upper88.com/
Chrome extension:https://chrome.google.com/webstore/detail/add-sense/bbiljflfafkaejgdebbnmcohpidgkejj
Not applicable

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

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

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

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

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

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

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

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

Not applicable

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

define( [

],

function ( ) {

  return {

  paint: function () {

  // This segment will be called every time

  // the visualization needs to handle the

  // change induced by an invalidation

  }

  };

} );