Get Free Trial

String comparison in IF statement ? version 2.8.13

Answered
Thomas Orré asked on July 1, 2021

Does string comparison work in version 2.8.13 ? I’d like to use something like :
 
If (Column1 == ‘Apple’, count(“Column1”), 0)
 
Thanks 

5 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster July 2, 2021

Hello, Thomas,
 
Thank you for writing to us.
 
Our team would like to kindly explain that comparing string members in the calculated value formula is not supported. This is because, by design, the calculated value functionality was intended for values, not hierarchies.
 
Please let us know if you have any other questions.
 
Kind regards,
Illia

Public
Thomas Orré July 5, 2021

Hello Illia, 
 
Thank you for your answer,
 
Ok, then as a Workaround, I guess I can replace string values by integer, for instance “Present” > 1, “Absent” > 0, “Other” > 2 ?
I tried to test a calculated value formula on numerical values, but I can’t get it to work…
My table contains a column ‘Age’, and some values are ’19’ (image 1 in the attached file), in the floating point number format.
However, I do not manage to count thoses values. I’ve tried the following formula :
if(“Age” == 19, count(“Age”), 0)  => returns “0”  (see image 2, 3, 4 in the attached file)
 
Even if I remove the “Période” parameter as “Rows” (“Lignes” in my language) (see image 5), if(“Age” == 19, count(“Age”), 0)  returns “0” (see image 6).
 
Can you tell me how to be able to count a recurring numerical value ? 
Kind regards
 
Thomas
 
 
 

Attachments:
FlexMonster_img.png

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster July 6, 2021

Hello,
 
We want to confirm that you can replace string values with associated numbers as a workaround.
The issue you are facing can be resolved by setting individual property of the calculated value to true. This parameter defines whether the formula is calculated using raw values or using aggregated values. In your case, raw values should be used. Otherwise, Flexmonster will sum “Age” first, and apply the condition afterward.
 
Here is a JSFiddle for demonstration: https://jsfiddle.net/flexmonster/wr8yhpz1/. You can configure it using UI by selecting “Calculate individual values” option or “Calculer les valeurs individuelles” with localization applied.
 
Please let us know if it helps.
Looking forward to your feedback.
 
Kind regards,
Illia

Public
Ali Avci November 12, 2021

What about booleans? If I convert “Yes” and “No” to booleans, would this work?
Let’s say I have data similar to the following:

[{
name: "James",
passed_exam: true,
}, {
name: "James",
passed_exam: false
}, {
name: "Mike",
passed_exam: false
}, {
name: "Mike",
passed_exam: false
}]

I would like to map the percentage of “passed_exam” by name. How can this be done?
Expected outcome:
Name:              Pass rate
James                50%
Mike              0%

Public
Vera Didenko Vera Didenko Flexmonster November 16, 2021

Hello,
 
Thank you for your question.
 
Currently, Flexmonster supports only number comparisons in calculated value formulas.
Still, it is possible to achieve the desired output without applying comparisons.
 
First, we suggest converting booleans/strings to numbers:

[{
"name": "James",
"passed_exam": 0
},
{
"name": "James",
"passed_exam": 1
},
...
]

or adding a numeric representation of the field that will be used for the calculations:

[{
"name": "James",
"passed_exam": false,
"passed_exam_n": 0,
},
{
"name": "James",
"passed_exam": true,
"passed_exam_n": 1
},
...
]

 
Next, our team suggests one of the following approaches:
 

  1. Using an average aggregation: 

    The "Pass Rate" output can be achieved by applying an average aggregation.
    Here is a JSFiddle example: https://jsfiddle.net/flexmonster/083myjgL/.

  2. Creating a calculated value:

    We can calculate the exam pass rate with the following formula:
    "sum('passed_exam') / count('passed_exam') * 100"

    We have prepared a JSFiddle for illustration: https://jsfiddle.net/flexmonster/fh3raLt8/.

    In the examples, we formatted the data as percent via number formatting.
    For more details on calculated values, please refer to our Calculated values guide.

 

We hope this helps! Feel free to reach out should any additional questions arise.
 
Kind regards,
Vera

Please login or Register to Submit Answer