calculated field - if value starts with .. select this: SOLVED

Hi,

i have a question about calculated fields.

Use Case is: We'd like to cluster living-areas. 

Therefore i need something like a calculated field thats selects for example Reagion1 if the zipcode in the linked field/module starts with 3.

Thanks!

Parents Reply Children
  • Certain it should be a number (either integer or float).

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • now it says: the formula must be boolean ..

    i'm going crazy

    the whole workaround.

    all the fields are in the same module.

    i use a related formula to get the first 2 digits of the zipcode.

    then i'd like to use the formular to set a region as value defined by the first 2 digits.

    zipcode it textfield - out of the box

    short zipcode - i tried all number fields

  • Hi Lennart Gebauer,

    I hear you on feeling crazy in situations like this.

    In this scenario, you are working with multiple functions in multiple formulas across multiple fields and field types. Because the outputs of some functions or the data types of fields might not be the data type the function they are embedded in need, you can get confusing errors that are difficult to chase down when dealing with the whole.

    Try replacing the field variables with the numbers saved in those fields and see if the formula still fails the same way, a different way, or works out. If it works, then the issue is in the field being called in the variable. Either the data on the database is not what you think is in that field, or the datatype of that field is not what is needed. If it fails the same way, it could be that one of the embedded functions is outputting a string in spite of the use of a number, and another function wrapped around it might be necessary to change the output of the embedded function.

    If the above modifications do not lead to a solution, there are other options. You could break the larger formula into parts in a textfield and see what the functions/formulas are outputting when broken down into parts. This often reveals surprises to me.

    If none of the above works, then it sounds like we will need the names, datatypes, and formulas in all relevant fields so we can build out a version on our ends and see if we can reproduce and narrow down the root cause along with you.

    I hope this helps!

  • Hi Lennart Gebauer,

    this requires a transformation of the textvalue into float.

    The following formula will to the trick but requires a second field (that does not need to be in the layout)

    It looks like this:

    What did I do?

    Initially I pulled the first two characters from the zip code field into the copyzip_c float field with this formula

    subStr($billing_address_postalcode,0,2)

    The field looks like this in studio

    Then I added this formula in my Sales Region field. Most important is the "Sonstige" part to catch all not mathcing results like a zip code that is written like D-44892 etc.

    ifElse(equal($copyzip_c,"10"),"City A",
    ifElse(equal($copyzip_c,"20"),"City B",
    ifElse(isWithinRange($copyzip_c,33,45),"Region A",
    ifElse(isWithinRange($copyzip_c,51,58),"Region B",
    ifElse(isWithinRange($copyzip_c,60,90),"Region C",
    "Sonstige"
    )))))

    Works like a charm!

    Viel Spaß damit :-)

    Cheers

    Björn Canales Pfisterer

    Technical Support Manager

    provalida GmbH

  • Hi Björn,

    thanks for the detailed Help!

    It works now and i see the troubleshooter.

    Sometimes it's in the detail!

    Have a good day

    Lennart

  • Hey Patrick,

    thanks for the words, sometimes it's quite difficult to get through the small details.

    It helped as well for other projects.

    Take care!

    Lennart

  • Would be glad if you can mark this thread as solved for helping others searching for a solution :-)

    Grüße

    Björn