[Ja...] Posted November 16, 2023 Share Posted November 16, 2023 I am trying to use a result element to change a result to zero if it is negative. Can someone tell me how to fix this formula or where I can find a list of functions that can be used in a result element.IfThen.pdf Link to comment Share on other sites More sharing options...
[Mi...] Posted November 16, 2023 Share Posted November 16, 2023 Edit: Norberts method is way better Use a variable. //in Presettings of the Result Element result = getActual("Result Element1").actual if result < 0 then result = 0 endif Then put the variable "result" or whatever you want to call it in the result element formula Link to comment Share on other sites More sharing options...
[No...] Posted November 16, 2023 Share Posted November 16, 2023 If / then phrases do not work in formula fields, only in PCM parameter fields and files To get your your desired result without using parameters, use the following alternative: getActual("Result Element1").actual * ord(getActual("Result Element1").actual >= 0) This multiplies the value of the first result element with the result of a test on whether it's positive. Since comparisons return only "true" or "false", you need the ord() function to convert the boolean value into a number (true = 1, false = 0) Link to comment Share on other sites More sharing options...
[Ja...] Posted November 16, 2023 Author Share Posted November 16, 2023 Please sign in to view this quote. I don't fully understand that but it works great. Thank you. Link to comment Share on other sites More sharing options...
[No...] Posted November 16, 2023 Share Posted November 16, 2023 Please sign in to view this quote. So let me explain (because constructs like this one are extremely useful sometimes): The formula works in three steps (marked in red): 1.) get the actual value of result element 1: getActual("Result Element1").actual * ord(getActual("Result Element1").actual >= 0) 2.) Test whether the value of result element 1 is positive (it's the opposite of testing for "negativeness") getActual("Result Element1").actual * ord(getActual("Result Element1").actual >= 0) Why test for the opposite? Because we need the correct boolean value for the third step: 3.) Convert boolean result to a number and multiply it with the result of step 1: getActual("Result Element1").actual * ord(getActual("Result Element1").actual >= 0) So, if step 1 gives us a positive result, let's say 25.2, then step 2 returns "true". Step 3 converts the "true" to the number "1" and multiplies it with step 1: 25.2 * 1 = 25.2 If step 1 returns a negative number, say -25.2, then step 2 returns "false", which converts to "0" in step 3. The following multilpication thus gives us -25.2 * 0 = 0 Link to comment Share on other sites More sharing options...
[Ke...] Posted November 16, 2023 Share Posted November 16, 2023 Norbert, This is an ingenious method, and an excellent explanation, thank you. Link to comment Share on other sites More sharing options...
[He...] Posted November 16, 2023 Share Posted November 16, 2023 Norbert: Nice job! I've never thought of that usage for ord(). I will remember that and probably use it sometime. However in this case a simple max() would do the trick. max(0,getActual("Result Element1").actual) If getActual("Result Element1").actual is positive it will be bigger than 0 and the max will return the value. If it is smaller than 0 the max will return 0. Link to comment Share on other sites More sharing options...
[No...] Posted November 17, 2023 Share Posted November 17, 2023 Please sign in to view this quote. Some programming languages with automatic datatype conversion even allow you to multiply with the boolean directly. I tried that first, but failed of course. I onlyl recently found ord() in the list of functions. Please sign in to view this quote. Very true. Amazing how even a short piece of code can be optimized even further 😃 Thumbs up! Link to comment Share on other sites More sharing options...
[Je...] Posted November 30, 2023 Share Posted November 30, 2023 I am a huge fan of these innovative approaches. Keep them coming! Link to comment Share on other sites More sharing options...
[Ma...] Posted December 1, 2023 Share Posted December 1, 2023 Hello. I wonder if it is possible, without the PCM function, to construct a formula that, for example, will check getActual("Result Element1").actual > getActual("Result Element2").actual and if it is true, it will substitute getActual("Result Element3"). actual and if not, it will substitute getActual("Result Element4").actual. Do you have any idea for this? Regards. Link to comment Share on other sites More sharing options...
[Da...] Posted December 1, 2023 Share Posted December 1, 2023 Please sign in to view this quote. Right click on Result element characteristic then click condition and try to do it there. Link to comment Share on other sites More sharing options...
[No...] Posted December 1, 2023 Share Posted December 1, 2023 Please sign in to view this quote. What exactly do you mean by "substitute"? Which element shall be substituted by what? Link to comment Share on other sites More sharing options...
[Ma...] Posted December 2, 2023 Share Posted December 2, 2023 Please sign in to view this quote. I solved this problem using patterns in Result Element. Before I tell you how I did it, let me explain why I needed it. Well, I had the Max and Min dimensions selected from a certain number of points. Of these points, I had to choose the one that was the furthest from the deviation, for example 2. Therefore, I needed to calculate the absolute value for the Min and Max dimensions. And when I already knew the absolute value of the farthest deviation, I needed to replace it with the Min or Max deviation corresponding to the largest absolute value. For this purpose I used the function: 1 Max Result 2 Min Result 3 Result Element Absolute value Max sqrt(squared(getActual("Max_1").actual-(getActual("2").actual))) 4 Result Element Absolute value Min sqrt(squared(getActual("Min_1").actual-(getActual("2").actual))) 5 Result Element ORD Max getActual("Max").actual * ord(getActual("War Bez_Max").actual > getActual("War Bez_Min").actual) 6 Result Element ORD Max getActual("Min").actual * ord(getActual("War Bez_Max").actual < getActual("War Bez_Min").actual 7 Deviation (getActual("ORD_Max").actual+getActual("ORD_Min").actual) It is possible that there is an easier way to determine this deviation, but I haven't found it yet. I will add that I do not have the PCM function. Regards Link to comment Share on other sites More sharing options...
[He...] Posted December 6, 2023 Share Posted December 6, 2023 This is a PCM solution but the last line is everything compressed in a single line which can be written into a single resultelement. //Get the two values Value1 = getActual("MAX").actual Value2 = getActual("MIN").actual //Create a list with the absolute values. indexOfMaxValue will give you the index of the largest absolute value (the biggest deviation). WorstIndex = list(abs(Value1),abs(Value2)).indexOfMaxValue //The worst value with its sign will be the same index of the same list but without the absolute values WorstValue = getParameterNamed(list(Value1,Value2),WorstIndex) //Now this can be substituted into one single long formula in a result element getParameterNamed(list(getActual("MAX").actual,getActual("MIN").actual),list(abs(getActual("MAX").actual),abs(getActual("MIN").actual)).indexOfMaxValue) Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in