Mixpanel Community Icon

Creating a Custom Property Using Existing User Properties

·
·

I have 2 user properties where one may contain data and the other may contain data. I want to create a new custom property where the property with data is used. How do I do this?

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

    Hi Bradley A., 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
    ·
    ·

    You can create a custom property in Mixpanel that uses data from whichever of your two user properties contains data. This is a common use case that can be handled with comparison operators and conditional logic.Here's how to create this custom property: 1. Click the plus button to the right of the search bar, then select "User Property" to open the property builder. 2. Give your property a name. 3. In the formula bar, you can use comparison operators to check if a property has data and then return the appropriate value.For example, if you have two properties "Property1" and "Property2", you could use a formula like this: LBKSIF(Property1 != null, Property1, Property2)LBKSThis formula checks if Property1 has a value (is not null). If it does, it returns Property1's value. If Property1 is null, it returns Property2's value instead.You can apply this custom property locally to your report by clicking "Apply", or save it permanently for use in other reports by clicking "Save". If you want to share it with colleagues, you can use the "Save and Share" option.Custom Properties documentation provides more details on creating and saving custom properties.Remember that custom properties can use various comparison operators like ==, !=, > , <, > =, and <= to create conditional logic in your formulas. You can also use the Ctrl + Space keyboard shortcut while writing your formula to see all available functions and their descriptions.

    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.

  • Avatar of Bradley A.
    Bradley A.
    ·
    ·

    kapa.ai can i use the coalesce function?

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

    Let me check the knowledge base for you again. One moment! 📚

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

    Yes, you can use the COALESCE function in Mixpanel's custom properties to achieve what you're looking for. The COALESCE function is specifically designed to return the first non-null value from a list of expressions, which is perfect for your use case where you want to use whichever of your two user properties contains data.Here's how you can use it: LBKSCOALESCE(Property1, Property2)LBKSThis formula will return the value of Property1 if it's not null; otherwise, it will return the value of Property2. If both properties are null, the result will be null.This is a more concise way to write the IF statement I mentioned earlier (IF(Property1 != null, Property1, Property2)), and it's particularly useful when you need to check multiple properties in sequence.When creating your custom property, you can press Ctrl + Space in the formula editor to see all available functions, including COALESCE, along with their descriptions.Custom Properties documentation provides more information about the various functions you can use when creating custom properties in Mixpanel.

    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.

  • Avatar of Bradley A.
    Bradley A.
    ·
    ·

    kapa.ai COALESCE is not an option and I cant use null either if I use the IF statement

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

    Let me check the knowledge base for you again. One moment! 📚

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

    I apologize for the confusion in my previous responses. You're right that COALESCE is not available as a function in Mixpanel's custom properties, and the null keyword isn't directly used in the IF statement syntax.Looking at the available functions in Mixpanel's custom properties, you can use the defined() function to check if a property exists or has a value, and then use the if function with the correct syntax. Here's how you can create a custom property that uses the first property that contains data: LBKSif(defined(Property1), Property1, Property2)LBKSThis formula checks if Property1 is defined (has a value). If it is, it returns Property1's value. If Property1 is not defined, it returns Property2's value instead.According to the Mixpanel documentation, the defined() function "Determines if a value exists. If a property is not defined on a parent event or profile, this will return false, otherwise this will return true." This is the appropriate function to use when checking for the existence of property values.Custom Properties documentation provides a complete list of available functions you can use in your formulas.If both properties might be undefined, and you want to handle that case, you could nest the if statements: LBKSif(defined(Property1), Property1, if(defined(Property2), Property2, "default value"))LBKSThis would return Property1 if it's defined, otherwise Property2 if it's defined, otherwise a default value.I hope this helps with creating your custom property!

    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.