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: 
Triss
Contributor
Contributor

Setting a range (min and max)

Hi all,

I'm hoping someone can give me some insight into how to create a range that has a min and max value.

I have a dataset akin to the following: 

Triss_2-1697608456747.png

Which when summed looks like this:

Triss_0-1697608146982.png

I am trying to generate the 'sum(BBServ) / sum(Serv)' column where values over 100% are rounded to 100% and values that are negative are either rounded to 0% or made null.

I have the following code that deals with the negatives, but I'm struggling to figure out how to also round the figures over 100%.

'rangemax(sum(BBServ),0)/rangemax(sum(Serv),0)'

This code generates the following:

Triss_1-1697608394853.png

I'd be very grateful for any assistance.

Thanks!

 

Labels (1)
6 Replies
Gabbar
Specialist
Specialist

Try using if statement:-
If(sum(BBServ) / sum(Serv)<0,0,If(sum(BBServ) / sum(Serv)>1,1,sum(BBServ) / sum(Serv)))

Aditya_Chitale
Specialist
Specialist

Try this:

if((Sum(BBServ)/sum(Serv)) < 0 or (RANGEMAX(sum(BBServ),0)/rangemax(sum(Serv),0)) = null() , RANGEMAX(sum(BBServ),0)/rangemax(sum(Serv),0) ,
if( (Sum(BBServ)/sum(Serv)) > 1 , 1 , RANGEMAX(sum(BBServ),0)/rangemax(sum(Serv),0)))

output:

Aditya_Chitale_0-1697613572134.png

 

Regards,

Aditya

Triss
Contributor
Contributor
Author

Thanks Gabbar. I forgot to include this in my original post, but I'm hoping to avoid using an if statement as it tends to slow things down considerably.

Gabbar
Specialist
Specialist

 Try this:-
Rangemin(Rangemax(Rangemax(Sum(BBserv),0)/Rangemax(Sum(Serv),0),0),1)

Triss
Contributor
Contributor
Author

Pretty close, but it seems to not like the double negatives:

Triss_0-1697666395179.png

 

Gabbar
Specialist
Specialist

Yes because you said that you made the code the solves values in negative and also showed making them null is ok, thats why i went with that,
otherwise this might work:-

Rangemin(Rangemax(Sum(BBserv)/Sum(Serv),0),1)