Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set expression to a long expression with multiple components

I have a model with four variables A, B, C, 😧

A = B * C / D

where

B, C, D are all variables with long expression:

B = sum(...)

C = count(...)

D = avg(...)

What I want is to apply a filter to calculate me A value of retail year 2016.

Below are two approaches I did:

Approach 1:

B_2016 = sum({$<retailyear={2016}> ...)

C_2016 = count({$<retailyear={2016}> ...)

D_2016 = avg({$<retailyear={2016}> ...)

A_2016 = $(B_2016) * $(C_2016) / $(D_2016)

Approach 2:

A_2016 = sum({$<retailyear={2016}> ...) * count({$<retailyear={2016}> ...) / avg({$<retailyear={2016}> ...)


Both approaches worked, but nasty: in Approach 1 I created too many variables, and in Approach 2 I created a extremely long and unreadable expression.


Is there a neat way, I can do something like:

A_2016 = <retailyear={2016}> B * C / D


Thank you!

3 Replies
tresesco
MVP
MVP

Try like:

A_2016 = Only({<retailyear={2016}>} Aggr(B * C / D, retailyear))

Not applicable
Author

Thank you! It worked with a bit adjustment:

A_2016 = Only({<retailyear={2016}>} Aggr($(B) * $(C) / $(D), retailyear))

marcus_sommer

One way could be to use variables with parameters, maybe in this way:

B = sum({$<retailyear={$1}>...)

C = count({$<retailyear={$1}>...)

D = avg({$<retailyear={$1}>...)

and then:

A = $(B(2016)) * $(C(2016)) / $(D(2016))

- Marcus