Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
abhaysingh
Specialist II
Specialist II

Logic Help..

Hi All,

I have one MinTemperature field and MaxTemperature Field. and one Current Temperature field..

I want to Calculate the Delta for this. e.g. Let Say Delta will be calculative on the basis of nearest Min or MaxTemp. in Below first case MinTemp is 1 and max is 5, but Current temp is 0.5 which is nearer to MinTemp so Delta is CurrentTemp - MinTemp.

MinTemp&''&MaxTempCurrentTempDelta
1 to 50.50.5
2 to 561
-1 to 5-1.20.2

Please suggest.

Thanks

Abhay

14 Replies
Gysbert_Wassenaar

Try rangemin(fabs(CurrentTemp-MinTemp),fabs(CurrentTemp-MaxTemp))


talk is cheap, supply exceeds demand
abhaysingh
Specialist II
Specialist II
Author

thanks gysbert,

I have one scenario in which Min-Max Range is -40 to -18 and current temp is  -17.5 and getting output 0.5, i think it should be -0.5. pls suggest

abhaysingh
Specialist II
Specialist II
Author

pls revert thanks

abhaysingh
Specialist II
Specialist II
Author

hi Please Revert

rubenmarin

Hi abhay, you can try with:

If(fabs(CurrentTemp-MinTemp)<fabs(CurrentTemp-MaxTemp), CurrentTemp-MinTemp, CurrentTemp-MaxTemp)

abhaysingh
Specialist II
Specialist II
Author

sry not working .. i have few combination of temp range

MinTemp               MaxTemp               Current Temp                    output                    by Above logic Getting O/P

-1                                   5                              -1.2                              -0.2                         -6.2

-40                                   -18                         -17.5                              -0.5                         0.5

pls suggest

thanks

rubenmarin

The second case is what you say to Gysbert it should be -0.5

For the first you can change the order of substration:

If(fabs(MinTemp-CurrentTemp)<fabs(CurrentTemp-MaxTemp), MinTemp-CurrentTemp, CurrentTemp-MaxTemp)

Digvijay_Singh

May be I misunderstood but its appearing like below to me-

As per your definition  in the initial details - "Delta is CurrentTemp - MinTemp" so -17.5-(-18) = 0.5.

Also in your first row - Mintemp is 1, Maxtemp is 5, currenttemp is 0.5 so as per your definition it should be 0.5-1=-0.5 but it is showing 0.5 in your table data.

I think you can use Ruben's expression if you want to consider sign else Gysbert's one. In your data there was indication that sign should be ignored while calculating delta. 3rd row should also have -0.2 if you are considering sign and your delta definition.

abhaysingh
Specialist II
Specialist II
Author

Hi Digvijay,

Thanks to correct me i am correcting my self below with desired output..

MinTemp                                                                      MaxTemp                                Output

1 to 50.5-0.5
2 to 561
-1 to 5-1.2-0.2
-40 to -18-17.50.5

Please suggest.

Thanks

Abhay

in New to QlikView Reply