Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
kevinpintokpa
Creator II
Creator II

Is it possible to re-use a measure in the expression for another measure?

Perhaps I am missing something obvious, but I am trying to do the following:

1) I define a measure named [Measure A].  This works fine and I can display it in a chart, table, etc.

2) I would now like to define a second measure named [Measure B] which would be [Measure A] divided by 1,000 (trivial example).  I have tried various syntaxes, but none of them work.  QlikSense does not complain but always returns a "-" where Measure B should be displayed.

Is this functionality not supported?  I am using Qlik Sense Desktop 2.01

1 Solution

Accepted Solutions
Josh_Good
Employee
Employee

Hi Kevin,

Yes that can be achieved in Qlik Sense but it isn't directly supported as you describe (yet).  What you need to do is load the expression in as variables.  You can type this in directly in the Data Load editor but I find it much easier to just create a data set (e.g. Excel spreadsheet or database table) that contain the expression information.

In the Data Load Editor you can use a script like the one below to load the expression as variables into Qlik Sense.  Then when you create the measures in Qlik Sense use the 'dollar sign expansion' format to tell Qlik Sense to evaluate the text as an expression.  For example if the variable called:

    vSales

is set to be:

    Sum(Sales)

then the expression used for the measure would be:

$(vSales)

I've attached an excel sheet with some epression in it an a sample QVF to help illustrate this.

-Josh

Qlik

VariablesTable:

LOAD

    VariableName,

    VariableValue

FROM [lib://Desktop/Expression Sample.xlsx]

(ooxml, embedded labels, table is Sheet1);

//* Set Equation variables

//* The following loop allowing for loading numerous variables dynamically,

//* without having to call them by name.

for i=0 to noofrows('VariablesTable')-1

  LET var_name= peek('VariableName',i,'VariablesTable');

  LET $(var_name) = peek('VariableValue',i,'VariablesTable');

  TRACE Load Variable: $(var_name) = $($(var_name));

next i

Drop Table VariablesTable;

View solution in original post

8 Replies
Josh_Good
Employee
Employee

Hi Kevin,

Yes that can be achieved in Qlik Sense but it isn't directly supported as you describe (yet).  What you need to do is load the expression in as variables.  You can type this in directly in the Data Load editor but I find it much easier to just create a data set (e.g. Excel spreadsheet or database table) that contain the expression information.

In the Data Load Editor you can use a script like the one below to load the expression as variables into Qlik Sense.  Then when you create the measures in Qlik Sense use the 'dollar sign expansion' format to tell Qlik Sense to evaluate the text as an expression.  For example if the variable called:

    vSales

is set to be:

    Sum(Sales)

then the expression used for the measure would be:

$(vSales)

I've attached an excel sheet with some epression in it an a sample QVF to help illustrate this.

-Josh

Qlik

VariablesTable:

LOAD

    VariableName,

    VariableValue

FROM [lib://Desktop/Expression Sample.xlsx]

(ooxml, embedded labels, table is Sheet1);

//* Set Equation variables

//* The following loop allowing for loading numerous variables dynamically,

//* without having to call them by name.

for i=0 to noofrows('VariablesTable')-1

  LET var_name= peek('VariableName',i,'VariablesTable');

  LET $(var_name) = peek('VariableValue',i,'VariablesTable');

  TRACE Load Variable: $(var_name) = $($(var_name));

next i

Drop Table VariablesTable;

kevinpintokpa
Creator II
Creator II
Author

Thanks, that makes sense and I've used the approach in QlikView documents before.

It would be a good feature to add to Qlik Sense, allowing further for easy reuse of metrics and dimensions.

Josh_Good
Employee
Employee

Fully agree.  It is on our roadmap as an improvement.

-Josh

Qlik

PS please close this discussion if appropriate.

Anonymous
Not applicable

Hi, Josh,

Is there an update on this?

Thanks very much

Zhihong

Josh_Good
Employee
Employee

Hi Zhihong,

At this time it remains on our roadmap.

-Josh

Qlik

joydipp1988
Creator
Creator

Hi Kevin,

Can you please send one excel with some dummy entries(max 5 entries) in it? Excel should have 2 sheets; one is Input_data, which u feed to QlikView and second sheet is Output_data, which shows the output. Please share it here. I hope to give you another solution.

Regards,

Joy

Not applicable

Hi,

Is there any news on this?

Possible in Version 3.0 ?

Regards,

Andreas

genissarettic
Contributor
Contributor

Hi,

Is there any news on this?

Today is 2019 dec 16!

Regards,

Genni