# Qlik Sense App Development

Not applicable

## Set expression to multiply factor based on range

Hello,

Below are the table structures I have:

Events:

Event, EventDate, EventAmount, EventOnTime, EventHappened

1, 1/1/2017, \$100, 1, 1

2, 1/1/2017, \$200, 0, 1

3, 1/2/2017, \$50, 0, 1

4, 1/31/2017, \$500, 1, 1

];

Percent of events that happened on time for the Month of Jan 2017 would be (1+0+0+1)/4=50% (Let this number be called P)

Factor:

FactorType, MinPercent, MaxPercent, Factor

A, 0%, 25%, 100%

A, 26%, 75%, 60%

A, 76%, 100%, 0%

];

In the visualization, I have created a line chart which shows the EventAmount by Month and for multiple Years. The chart looks something like like this.

The actual requirement is to multiply the EventAmount by Factor based on the range in which "P" belongs. In this case, for Jan 2017- EventAmount(\$850)*Factor(60%)=\$510. \$510 is the number which has to be represented in the line chart.

How to write set expression for the above requirement?

Deepika

Tags (1)
3 Replies
Not applicable

## Re: Set expression to multiply factor based on range

Hello,

try this expression:

=

if(

(aggr ( sum(EventOnTime), monthyear) / count(total EventOnTime) ) <=0.25, 1, if(

(aggr ( sum(EventOnTime), monthyear) / count(total EventOnTime) ) <=0.75, 0.6, if(

(aggr ( sum(EventOnTime), monthyear) / count(total EventOnTime) ) <=1, 0))) * EventAmount

Not applicable

## Re: Set expression to multiply factor based on range

Is there a possibility to do this without hard-coding the factor values; cause the factor values can change.

Not applicable

## Re: Set expression to multiply factor based on range

you can add these tables, so the expression is not hardcoded in the dashboard but in the script, it is hard to link it to the Factor table hence there is no identifier to each range

Try these in the script:

Events1:

MonthName(Date(EventDate)) as monthyear

resident Events;

drop table Events;

test:

monthyear,

sum(EventOnTime)/ count( EventOnTime) as Factor,

if( sum(EventOnTime)/ count( EventOnTime)<=0.25 , 1,

if(sum(EventOnTime)/ count( EventOnTime)<=0.75 ,0.6 ,

if(sum(EventOnTime)/ count( EventOnTime)<=1 ,0))) as Total11

resident Events1

group By monthyear;