Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

user defined function to select values from a table for subsequent calculation

Hey,

I use this user defined function to calculate the water content of air. :

0.622 * (rel. hum * saturated vapour pressure) / (air pressure - rel. hum * saturated vapour pressure)

-->

SET udf_water_content = Num(0.622*($1*$2)/(($3-$1*$2)));

But now I would like to get the saturated vapour pressure of the measured temperature instead of a fix value.

water_content = $(udf_water_content(humidity,=$(VapPress(=$(round(temperature))),101300));

I have a table with temperatures from -20 to 99 °C with the associated saturated vapour pressures. So how can I define the VapPress function to select the vapour pressure of the associated temperature? Attached you can see an extract of the table with the preassures. The meassured temperatures are floats, so I would need to round them as well.

temp
saturated_vapour_pressures
171936,2
182062
192196
202337
212485
222642

Thanks for feedback.

BR

Henrik

14 Replies
MarcoWedel

Hi,

instead of using a lookup table you could also calculate the saturated vapour pressure

e.g. as defined by the International Association for the Properties of Water and Steam (International Association for the Properties of Water and Steam😞

http://www.iapws.org/relguide/IF97-Rev.pdf

LET vN1  = 0.11670521452767e4;

LET vN2  = -0.72421316703206e6;

LET vN3  = -0.17073846940092e2;

LET vN4  = 0.12020824702470e5;

LET vN5  = -0.32325550322333e7;

LET vN6  = 0.14915108613530e2;

LET vN7  = -0.48232657361591e4;

LET vN8  = 0.40511340542057e6;

LET vN9  = -0.23855557567849;

LET vN10 = 0.65017534844798e3;

SET vϑ = ($1+273.15+$(vN9)/($1+273.15-$(vN10)));

SET vA = (pow($(vϑ($1)),2)+$(vN1)*$(vϑ($1))+$(vN2));

SET vB = ($(vN3)*pow($(vϑ($1)),2)+$(vN4)*$(vϑ($1))+$(vN5));

SET vC = ($(vN6)*pow($(vϑ($1)),2)+$(vN7)*$(vϑ($1))+$(vN8));

SET vp = pow(2*$(vC($1))/(-$(vB($1))+pow(pow($(vB($1)),2)-4*$(vA($1))*$(vC($1)),0.5)),4)*1e6;

SET VapPress = Dual(Num($(vp($1)),'0.0')&' Pa',$(vp($1)));

SET udf_water_content = Num(0.622*($1*$2)/(($3-$1*$2))*1000);

tabHumidity:

LOAD *,

    $(udf_water_content(rel.hum, sat_vap_pres, 101300)) as water_content;

LOAD *,

    $(vp(temp)) as sat_vap_pres;

LOAD Dual(RecNo()&' RH%', RecNo()/100) as rel.hum,

    Dual(IterNo()-1&' °C', IterNo()-1) as temp

AutoGenerate 100

While IterNo()<102;

tabSatVapPress:

LOAD temp,

    $(VapPress(temp)) as VapPress

FROM [http://community.qlik.com/thread/147952] (html, codepage is 1252, embedded labels, table is @1);

QlikCommunity_Thread_147952_Pic1.JPG

QlikCommunity_Thread_147952_Pic2.JPG

QlikCommunity_Thread_147952_Pic3.JPG

hope this helps

regards

Marco

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Any chance you could upload a sample qvw?

-Rob

Not applicable
Author

attached you can find a sample qvw with an excel sheet including some sample data and the saturated vapour pressures table. Thanks for reviewing!

Not applicable
Author

Thanks a lot for the huge effort you invested to help me out, but I hope to find a much easier solution. Especially to transfer the approach to similar issues, because this is a very unike solution.

BR
Henrik

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I looked at your qvw and realized I took you down the wrong path with the Set expression. That is not going to work row by row. This will work as a chart expression though.

  SET udf_svp = only(if(vp_temp = Round($1), saturated_vapour_pressures));


then

  $(udf_svp(temperature))


I don't know if it fits your original requirement, but in your script you could add

  .round(temperature) as vp_temp

to the data table which would create a linkage between temperature and saturated_vapour_pressures.


-Rob