Hi all,
I would like to have my Conversion % column dynamically change decimal places according to the values it represents. The AUTO feature is not consistent, it does not automatically determine the appropriate number of decimal places.
As an example if the conversion values are small, I’d like to see decimals (i.e. 3.2%). On the other hand, if values are big enough decimals become irrelevant (i.e. 40%)
How can I achieve that? a formula maybe?
Thanks @wstevens01 . I was trying to replicate that with percentages, but I cannot make it work.
My actual use case is:
IF Conversion% is less than 10% then return Conversion% with one decimal (example: 8.2%)
ELSE return Conversion% without any decimal (example: 14%).
It looks like we’re wrestling with both precision and the behavior of round().
With percentage decimals, less than 1/greater than 0, you need that extra precision to get the correct round() behavior, but that extra precision is the problem that you’re trying to solve for.
The best I was able to do was to show that if you’ll get reasonable behavior if you pre-calculate the percent value (e.g. multiple by 100):
Here are the two calculated fields:
crv_dynamic: ifelse(CRV >= 0.1, round(CRV, 0), round(CRV, 1) )
crv_pct_dynamic: ifelse({CRV_pct} >= 10.0, round({CRV_pct}, 0), round({CRV_pct}, 1) )
This does lead to a display problem, because if you display the number as a percentage, you’ll get the wrong value. But the actual numbers are correct.
I’m guessing that you’ll end up showing a decimal or two for percentages over 10.
Thanks so much again for trying to find a solution with me.
Unfortunately, it does not seem to work with me. Not sure what I might be doing wrong, if anything.
This is what I meant about the display problem. To concat the % sign, you have to cast the number to a string and that automatically adds the decimal.
Eriks idea about looking for the decimal in the string is what I was thinking as well, but you’ll still have to determine which numbers to remove the decimal and which numbers to leave the decimal.
I’ll noodle more on it the morning, but I think that you’ll have to add the string manipulation to the ifelse statement.
Notice that the substring() arguments are hardcoded to pick the first 3 characters. I think that’s OK because for a percent less than 10, it will always be a single digit number. If that’s true, than this should work for you.
Also note that as a string, you can’t do any numeric processing, like a sum() or max().
I realized that using the string functions to manage the decimal, you don’t need the round() function. This calculation produces the same result as above: