Mixpanel Community Icon

Sum Character Length of Two Event Properties with Fallback to Zero

·
·

What formula can I use in 'create event property' to sum the length of characters in 2 event properties, however, if either of the event properties do not exist then the event property should be recorded as 0 characters instead of FALSE

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Hi Chris S., Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> đź‘‹

    Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    To create a custom property that sums the length of characters in two event properties while handling undefined properties as 0 characters, you can use a combination of the len() function and the defined() function in Mixpanel's custom property formula.Here's a formula you can use: LBKS(if(defined(properties["first_property"]), len(properties["first_property"]), 0)) + (if(defined(properties["second_property"]), len(properties["second_property"]), 0))LBKSThis formula works by: 1. Checking if each property exists using the defined() function 2. If the property exists, it calculates its length using the len() function 3. If the property doesn't exist, it uses 0 instead 4. Finally, it adds the two values togetherThe len() function in Mixpanel returns the length of a string or list, as documented in the custom properties reference Mixpanel Custom Properties Functions.You can create this custom property by clicking the plus button to the right of the search bar in your Mixpanel report, selecting Event Property, and then entering this formula in the formula field. Remember to replace "first_property" and "second_property" with the actual names of your event properties.

    kapa.ai is still learning and improving, please let me know how I did by reacting below.

    ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.