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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Montezuma213
Contributor
Contributor

Multiple Statements in an Expression

Was wondering if someone could help me find a better way to do this.  

I have about  20 ratios that I need in a chart.  I'm struggling with an expression to add them all into one expression. 

 

Example 

1. Select a Filter (Product)

2. Chart calculates the Ratio (um({$<Measure = {'AAAA'}>} Visits) / sum({$<Measure = {'BBB'}>} Visits)))

 

if(Product = 'xxx1', sum({$<Measure = {'AAAA'}>} Visits) / sum({$<Measure = {'BBB'}>} Visits))

if(Product = 'xxx2', sum({$<Measure = {'CCCC'}>} Visits) / sum({$<Measure = {'DDD'}>} Visits))

if(Product = 'xxx3', sum({$<Measure = {'EEEE'}>} Visits) / sum({$<Measure = {'FFFF'}>} Visits))

Thanks in Advance

Labels (2)
4 Replies
sasikanth
Master
Master

HI, 

Try Pick() function

 

=Pick(match(Product ,''xxx1','xxx2','xxx3'),

sum({$<Measure = {'AAAA'}>} Visits) / sum({$<Measure = {'BBB'}>} Visits),

 sum({$<Measure = {'CCCC'}>} Visits) / sum({$<Measure = {'DDD'}>} Visits),

sum({$<Measure = {'EEEE'}>} Visits) / sum({$<Measure = {'FFFF'}>} Visits))

 

Thanks, 

Sasi

marcus_sommer

Why not doing the essential work within the script, for example with an extra table containing the product + measure information, like:

t: load * inline [
product, measureX, measureY
abc, AAAA, BBB
...
];

and then using an expression like:

sum({< Measure = p(measureX)>} Visits) / sum({< Measure = p(measureY)>} Visits)

Montezuma213
Contributor
Contributor
Author

I got the table to work, just cant get the expression to work.

 

Marcus, thank you for the reply.

This is what the table looks like..

LOAD*INLINE [
Offers, Offer_Clicked, Offer_Shows

[Insurance, Renter's Insurance (Clicked), Renter's Insurance (Shows),

expression: Cant seem to figure this part out. 

num(sum({$<Offers = {Offer_Shows}>} Visits)/sum({$<Offers = {Offer_Clicked}>} Visits),0.000)

marcus_sommer

You put the field-names as value-strings within the condition but you need to reference to the possible values of those fields which could be done like demonstrated above with p() - means the expression should look like:

num(sum({$<Offers = p(Offer_Shows)>} Visits)/sum({$<Offers = p(Offer_Clicked)>} Visits), '0.000')